View the Exhibit and examine the structure of the EMPLOYEES table.
Examine the following PL/SQL block:
DECLARE
TYPE EmpList
IS VARRAY(2) OF employees.employee_id%TYPE NOT NULL;
v_employees EmpList := EmpList();
BEGIN
DBMS_OUTPUT.PUT_LINE(v_employees.COUNT);
v_employees.EXTEND;
v_employees(1) := 30;
END;
/
Which statement is true about the outcome on executing the above PL/SQL block?
A.
It executes successfully and displays the value 2.
B.
It executes successfully and displays the value 0.
C.
It generates an error because EXTEND cannot be used for varrays.
D.
It generates an error because the declaration of the varray is not valid.
B
Oracle Database PL/SQL Language Reference 11g Release 1 (11.1)
Counting the Elements in a Collection (COUNT Method)
“For varrays, COUNT always equals LAST. You can increase or decrease the size of a
varray using the EXTEND and TRIM methods, so the value of COUNT can change, up to
the value of the LIMIT method.”
Following allows to exclude D:
https://docs.oracle.com/cd/B19306_01/appdev.102/b14261/collection_definition.htm#i33100
B
Notes
1) delete keep the placeholder of deleted element, so you can assign one value to the deleted element
2) trim doesn’t keep the placeholder, if trim encountered deleted element, trim include it in its tally.
3) deleted element is not included in .count
B.
EXTEND is one of the Oracle PL/SQL collection methods which is used with Nested Tables and VARRAYS
to append single or multiple elements to the collection.
1. EXTEND, which adds a single NULL instance.
2. EXTEND(n) which adds multiple NULL instances. The number of instances is specified by n.
3. EXTEND(n,m) which appends n copies of cell m to the collection.
http://psoug.org/definition/EXTEND.htm