PL-SQL 8-2 Practice
PL-SQL 8-2 Practice
PL-SQL 8-2 Practice
argument
Actual Parameters
Formal parameter
1. In your own words, describe parameters and the purpose they serve in PL/SQL
subprograms.
Parameters are used to pass values that may vary into a subprogram. They make
procedures more flexible; a procedure can be created once and then executed
many times
country and its capitol city. Name your procedure get_country_info. Save your
procedure
(p_country_id IN wf_countries.country_id%TYPE)
IS
v_country_name wf_countries.country_name%TYPE;
v_capitol wf_countries.capitol%TYPE;
BEGIN
SELECT country_name, capitol
FROM wf_countries
v_capitol);
END;
BEGIN
get_country_id(90);
END;
C. Re-execute the procedure from the anonymous block, this time using country_id
95. What
happens?
D. Retrieve your procedure code from Saved SQL and modify it to trap the
NO_DATA_FOUND
wf_countries.country_id%TYPE)
IS
v_country_name wf_countries.country_name%TYPE;
v_capitol wf_countries.capitol%TYPE;
BEGIN
FROM wf_countries
v_capitol);
EXCEPTION
END;
3. In your own words, describe what a formal parameter is and what an actual
parameter is. Also,
A formal parameter is the parameter in the header of a procedure that gives the
parameter a name
and datatype. An actual parameter is the value passed from the calling
environment when the
procedure is executed.
The formal parameter name is referenced within the procedure code. Actual
parameter can be
4. Procedure Exercise:
A. Write a procedure that displays the number of countries in a given region whose
highest
elevations exceed a given value. The procedure should accept two formal
parameters, one for
a region_id and the other for an elevation value for comparison. Use
(p_region_id wf_countries.region_id%TYPE
,p_elevation wf_countries.highest_elevation%TYPE)
IS
v_count NUMBER(4);
BEGIN
FROM wf_countries
END;
B. Execute your procedure using the value 5 for the region_id and 2000 for the
highest elevation.
BEGIN
get_country_count(5,2000);
END;
C. DESCRIBE your procedure to check the names and datatypes of its formal
parameters.
DESCRIBE get_country_count
D. Retrieve your procedure code from Saved SQL and modify it to accept a third
formal parameter
region whose highest elevations exceed a given value and whose country name
starts with a
compare the first character of each country’s name with the third parameter value
(Hint: use
SUBSTR). Save your work again and DESCRIBE the modified procedure.
E. Write an anonymous block which declares three variables to store actual
parameter values for
the region_id, elevation, and area, and then executes the procedure passing these
values.
DECLARE
v_region_id wf_countries.region_id%TYPE := 5;
BEGIN
END;
F. Modify your anonymous block to use the same actual parameter values but pass
them to the
procedure in a different order: (5, ‘B’, 2000). Execute the block. What happens and
why?
DECLARE
v_region_id wf_countries.region_id%TYPE := 5;
BEGIN
END;
An ORA-06502 data conversion error is returned because the procedure call
cannot convert an actual