The AskTOM team is taking a break over the holiday season, so we're not taking questions or responding to comments. Please have a happy and safe festive season and as always, thanks for being a member of the AskTOM community.
Thanks for the question, Ningappa.
Asked: March 10, 2017 - 5:50 am UTC
Last updated: March 10, 2017 - 7:48 am UTC
Version: 3.0
Viewed 10K+ times! This question is
SQL> declare 2 type numlist is table of number index by pls_integer; 3 n numlist; 4 begin 5 execute immediate 'create table t ( x int )'; 6 for i in 1 .. 10 loop 7 n(i) := i; 8 end loop; 9 10 for i in 1 .. n.count loop 11 execute immediate 'insert into t values (:val)' using n(i); 12 end loop; 13 end; 14 / PL/SQL procedure successfully completed. SQL> SQL> select * from t; X ---------- 1 2 3 4 5 6 7 8 9 10 10 rows selected.
SQL> drop table t purge; Table dropped. SQL> SQL> create or replace 2 package pkg is 3 type numlist is table of number index by pls_integer; 4 end; 5 / Package created. SQL> SQL> SQL> declare 2 n pkg.numlist; 3 begin 4 execute immediate 'create table t ( x int )'; 5 for i in 1 .. 10 loop 6 n(i) := i; 7 end loop; 8 9 execute immediate 10 'declare 11 x pkg.numlist := :val; 12 begin 13 forall i in 1 .. x.count 14 insert into t values (x(i)); 15 end; 16 ' using n; 17 end; 18 / PL/SQL procedure successfully completed.
Check out more PL/SQL tutorials on our LiveSQL tool.
PL/SQL reference manual from the Oracle documentation library