Home » SQL & PL/SQL » SQL & PL/SQL » Submit a Table Name as a Parameter to a Procedure for Processing?
Submit a Table Name as a Parameter to a Procedure for Processing? [message #40321] Fri, 27 September 2002 05:53 Go to next message
Lloyd M. Terrell
Messages: 5
Registered: September 2002
Junior Member
How do I submit a table name as a parameter to a procedure? I have to develope PL/SQL code to process a number of tables. The only thing that changes are the table names. I need to do something as follows:

CREATE OR REPLACE PROCEDURE DO_SMTHG(table_name IN VARCHAR2)
BEGIN
...
UPDATE table_name
...
END;

Would I have to do something like:
UPDATE &table_name

in order to use the table name within the code?

The script I will be using to execute this procedure will look something like this (VMS System - This job will be scheduled to run over night):

SQLPLUS SCOTT/TIGER@MADDEV.WORD EXECUTE DO_SMTHG('DEPT');
SQLPLUS SCOTT/TIGER@MADDEV.WORD EXECUTE DO_SMTHG('EMP');
SQLPLUS SCOTT/TIGER@MADDEV.WORD EXECUTE DO_SMTHG('BONUS');
...

Thanks.
Re: Submit a Table Name as a Parameter to a Procedure for Processing? [message #40322 is a reply to message #40321] Fri, 27 September 2002 06:30 Go to previous message
Suresh
Messages: 189
Registered: December 1998
Senior Member
You will have to use Dynamic SQL.

If you are using 8i or above, you can use Execute immediate statement.

Execute immediate 'Update ' || table_name

or if you are using an Oracle version less than 8i use DBMS_SQL package.
Previous Topic: error returned calling a function
Next Topic: DECODE
Goto Forum:
  


Current Time: Sun Apr 28 21:36:00 CDT 2024