Home » SQL & PL/SQL » SQL & PL/SQL » Declaring table names as constants
Declaring table names as constants [message #47847] Thu, 23 September 2004 10:08 Go to next message
Ray Smith
Messages: 2
Registered: September 2004
Junior Member
I have a packaged procedure that updates several tables as part of a data mart. I would like to use consistent aliases for the tablenames throughout the package.

Here's a test procedure I thought should work:
CREATE OR REPLACE PROCEDURE test_constant_names
IS
my_cal CONSTANT VARCHAR2(30) := MYCALENDAR;
c_cal CONSTANT VARCHAR2(30) := CALENDAR;
BEGIN
INSERT INTO my_cal
SELECT * FROM c_cal;
COMMIT;
END;

Results in "PLS-00357: Table,View Or Sequence reference 'myschema.mytable' not allowed in this context" for rows 3 and 4. Also get ORA-00942 (table does not exist) for line 7.

How can I use and reuse constants for table names?
Re: Declaring table names as constants [message #47849 is a reply to message #47847] Thu, 23 September 2004 12:20 Go to previous messageGo to next message
Todd Barry
Messages: 4819
Registered: August 2001
Senior Member
First, you would need single quotes around those object names. Second, you need to use dynamic SQL anytime you are substituting object names at runtime.

execute immediate 'insert into ' || my_cal || ' select * from ' || c_cal;
Re: Declaring table names as constants [message #47854 is a reply to message #47849] Fri, 24 September 2004 12:18 Go to previous message
Ray Smith
Messages: 2
Registered: September 2004
Junior Member
My original intent was to simplify my code, and in this case (populating data mart tables) dynamic SQL will complicate things. Moving in the wrong direction.
Thanks for your input.
Previous Topic: random result from oracle select with join
Next Topic: Mirror characters
Goto Forum:
  


Current Time: Sat May 02 21:43:07 CDT 2026