Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Dynamic variable names

YogOct 5 2007 — edited Oct 5 2007
Hi,

Is there an easy way to dynamically build plsql in the same way as execute immediate works for sql as follows:

declare

v1 number := 10;
v2 number := 20;
v3 number := 30;
v4 number := 40;

v_return number;

begin

for x in 1..4 loop

[something like execute immediate] 'v_return := v'||x;

...do something with v_return....;

end loop;


end;


This is a trivial example but I like to be able to dynamically call variable names like this. It would save a lot of duplication because the only other way I can think of to do it would be repeat the same code for each instance.


Thanks
Yog
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 2 2007
Added on Oct 5 2007
7 comments
1,857 views