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 UPDATE statement with parameters for column names.

metalrayApr 18 2013 — edited Apr 18 2013
Hello,
On this* website I read "The SQL string can contain placeholders for bind arguments, but bind values cannot be used to pass in the names of schema objects (table or column names). You may pass in numeric, date, and string expressions, but not a BOOLEAN or NULL literal value"
On the other hand, in this 10444615 and many other
posts people use EXECUTE IMMEDIATE to create a dynamic UPDATE statement.

dynSQL:='UPDATE CO_STAT2 CO SET CO.'||P_ENT_B_G_NAME||' = '||P_ENT_E_G_WE||'
WHERE ST IN
(SELECT ST FROM STG_CO_STAT2_TEST CO WHERE
'||P_ST||' = CO.ST AND
CO.'||P_ENT_E_G_NAME||' > '||P_ENT_E_G_WE||' AND
CO.'||P_ENT_B_G_NAME||' < '||P_ENT_E_G_WE||');';
EXECUTE IMMEDIATE dynSQL ;

Since this statement is part of a Stored Procedure, I wont see the exact error but just get a ORA-06512.

The compiling works fine and I use Oracle 11g.

http://psoug.org/definition/EXECUTE_IMMEDIATE.htm
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 16 2013
Added on Apr 18 2013
8 comments
3,048 views