Tuesday, May 14, 2013

PL/SQL EXTEND

PL/SQL EXTEND

Definition:

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.

Example Usage:

The PL/SQL block below declares a PL/SQL table collection and appends the first cell at the end of the collection.

DECLARE

       type psoug_tab is table of number;
       ptab psoug_tab;

BEGIN

        ptab := psoug_tab();
        ptab.extend;
        ptab(1) := 100;
        dbms_output.put_line('value at index(1) is '||ptab(1));
        ptab.extend(5,1);
        dbms_output.put_line('value at index(4) is '||ptab(4));

END;



value at index(1) is 100

value at index(4) is 100



PL/SQL procedure successfully completed.

No comments:

Post a Comment