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. Note that EXTEND cannot be used with associative arrays. EXTEND has three forms:
- EXTEND, which adds a single NULL instance.
- EXTEND(n) which adds multiple NULL instances. The number of instances is specified by n.
- EXTEND(n,m) which appends n copies of instance m to the collection.
Note that forms one and two cannot be used for NOT NULL specified collections.
The PL/SQL block below declares a PL/SQL table collection and appends the first cell at the end of the collection.
TYPE PSOUG_TAB IS TABLE OF NUMBER;
PTAB := PSOUG_TAB();
PTAB(1) := 100;
DBMS_OUTPUT.PUT_LINE('VALUE AT INDEX(1) IS '||PTAB(1));
DBMS_OUTPUT.PUT_LINE(‘VALUE AT INDEX(4) IS '||PTAB(4));
VALUE AT INDEX(1) IS 100
VALUE AT INDEX(4) IS 100
PL/SQL procedure successfully completed.
Related Code Snippets: