The STUDENTS table with column LAST_NAME of data type VARCHAR2 exists in your database schema. Examine this PL/SQL block: Which two actions must you perform for this PL/SQL block to execute successfully?
A.
Replace the FOR loop with FOR name_rec IN names_varray.FIRST .. names_varray.LAST LOOP.
B.
Replace the L_NAME_TYPE declaration with TYPE 1_name_type IS VARRAY (25) OF SYS_REFCURSOR;
C.
Add name_rec name_cur%ROWTYPE; at the end of the DECLARE section.
D.
Replace the NAMES_VARRAY declaration with names_varray 1_name_type := 1_name_type ();
E.
Replace the NAMES_VARRAY declaration with names_varray 1_name_type := null;
F.
Add names_varray.EXTEND after the FOR …LOOP statement.
DECLARE
CURSOR l_name_cur IS
SELECT LAST_NAME
FROM EMPLOYEES
FETCH NEXT 25 ROWS ONLY;
TYPE l_name_type IS VARRAY(25) OF EMPLOYEES.last_name%type;
--names_array l_name_type; --WRONG --Reference to uninitialized collection
names_array l_name_type := l_name_type();
v_index INTEGER := 0;
BEGIN
FOR name_rec IN l_name_cur LOOP
names_array.EXTEND(); -- DONT OMIT IT, Or will get ERROR: Subscript beyond count
v_index := v_index + 1;
names_array(v_index) := name_rec.last_name;
DBMS_OUTPUT.PUT_LINE(names_array(v_index));
END LOOP;
END;
D,F Working code below
DECLARE
CURSOR l_name_cur IS
SELECT LAST_NAME FROM SIS.STUDENTS;
TYPE l_name_type IS VARRAY(25) OF SIS.STUDENTS.last_name%type;
names_array l_name_type := l_name_type();
v_index INTEGER := 0;
BEGIN
FOR name_rec IN l_name_cur LOOP
names_array.EXTEND();
v_index := v_index + 1;
names_array(v_index) := name_rec.last_name;
DBMS_OUTPUT.PUT_LINE(names_array(v_index));
END LOOP;
END;
/
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
orakell
Highly Voted 5 years, 2 months agoRakeshpro
Most Recent 2 years, 4 months agochrishillinger
2 years, 5 months agoBenjmaz
4 years agosudhirdavim
4 years, 1 month agoCosminCof
4 years, 2 months agopeguynya
4 years, 6 months ago