Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: Dynamic SQL and dynamic variable names

Re: Dynamic SQL and dynamic variable names

From: William Robertson <williamr2019_at_googlemail.com>
Date: 18 Jan 2007 02:52:13 -0800
Message-ID: <1169117532.923621.23470@q2g2000cwa.googlegroups.com>


saketkhanna_at_gmail.com wrote:
> I have a peculiar problem I've been working on for a while now...
>
> I am trying to call a procedure in a loop and pass the value of each
> column in a cursor.
>
> something like this:
>
> for v_cursor_columns in c_columns
> loop
> begin
> v_dynamic := 'BEGIN compare_proc ( v_cursor_columns.column_name)';
> execute immediate v_dynamic;
> end loop;
>
>
> Basically - I am trying to access variable in the current anonymous
> pl/sql block.
>
> However, I get this error whenever I try:
>
> PLS-00201: identifier 'v_cursor_diff.column_name' must be declared
>
> In some other parts, I am even trying to generate the variable name (in
> above example v_cursor_columns.column_name ) on the fly using
> concatenation.
>
> How can I accomplish these tasks?
>
> I've searched all the web I could, but couldn't find such an example.
> Someone mentioned that dynamic sql will access global variables only -
> Can someone please help me?

Shouldn't that be

v_dynamic := 'BEGIN compare_proc (:b1)';

for v_cursor_columns in c_columns
loop

    execute immediate v_dynamic USING v_cursor_columns.column_name; end loop; Received on Thu Jan 18 2007 - 04:52:13 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US