Let's take my FORALL statement from the function source code and see where is the problem:
forall i in 1..messages_tab.countIn a perfect world i could have written (without using an additional collection):
execute immediate
'insert into '|| p_owner||'.'||p_table
||'('||p_txt_col||',' || p_cnt_col ||') values(:1, :2)'
using messages_tab(i), subscripts_tab(i);
forall i in 1..messages_tab.count
execute immediate
'insert into '|| p_owner||'.'||p_table
||'('||p_txt_col||',' || p_cnt_col ||') values(:1, :2)'
using messages_tab(i), i;
However if you try to compile a program containing this FORALL statement, you'll get:
PLS-00430: FORALL iteration variable I is not allowed in this context
This is why i decided to use the additional collection called subscripts_tab.
This collection contains the subscripts of the elements themselves plus an offset corresponding to the size of the "chunk" of dbms_ouput messages that i retrieve every time (100 at a time if you look at the value maxbuf), so i populate the collection with the help of a bizarre hierarchical SQL statement courtesy of Tom Kyte using BULK COLLECT:
select level + kAnd this should end the dbms_output tormentone, a nice italian word meaning "some gossip, tune or jingle that keeps buzzing in your head and you can't get rid of".
bulk collect into subscripts_tab
from dual
connect by level <= maxbuf;
No comments:
Post a Comment