Taking table name as input in sql

独自空忆成欢 提交于 2021-01-29 04:37:44

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!