Vabs
Vabs

Reputation: 11

Taking table name as input in sql

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.

Upvotes: 1

Views: 831

Answers (1)

cagcowboy
cagcowboy

Reputation: 30828

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

Upvotes: 4

Related Questions