问题
I need to take a table name as input from user to my PL / SQL script and then update that table. I am not sure if this is possible because ORACLE might have problem parsing the script.
Please guild me as to how to solve this problem.
Thnx.
回答1:
Use EXECUTE IMMEDIATE. It allows you to build a SQL statement as a VARCHAR2 string and then execute that statement.
eg.
lStr := 'UPDATE '||table-name||' SET COLUMN-NAME = VALUE';
EXECUTE IMMEDIATE lStr;
COLUMN-NAME and VALUE can also be changed dynamically of course.
http://download.oracle.com/docs/cd/B12037_01/appdev.101/b10807/13_elems017.htm
来源:https://stackoverflow.com/questions/5429717/taking-table-name-as-input-in-sql