Friday, August 03, 2007

PLS-00430: FORALL iteration variable XYZ is not allowed in this context

As i wrote in my previous posting, it was my intention to explain why i used a collection for storing the indices of the messages collected from dbms_output buffer.

Let's take my FORALL statement from the function source code and see where is the problem:

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), subscripts_tab(i);
In a perfect world i could have written (without using an additional collection):
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 + k
bulk collect into subscripts_tab
from dual
connect by level <= maxbuf;
And 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".

No comments:

yes you can!

Two great ways to help us out with a minimal effort. Click on the Google Plus +1 button above or...
We appreciate your support!

latest articles