Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

A cursor with a select on a table that does not exist (yet)

631752Dec 21 2009 — edited Dec 22 2009
Hi,

I am trying to write a stored procedure that in essence will transfer certain data to a temporary table
to avoid it being deleted from another table. Later on, this extracted data is reinjected back into the
original source table. The database is Oracle 10g.

Firstly, a temporary table is created and data is transferred into it as follows:

create table t_temp as select * from t_data where custid='XYZ';

To reinject the data back into the original table t_data I wish to use a cursor and a BULK COLLECT:

The cursor would is something like:
CURSOR c_TEMP IS SELECT * from t_temp;

A variable l_data will hold the data from the temporary table to be reinjected into the original:

TYPE ARRAY IS TABLE OF t_data%ROWTYPE;
l_data ARRAY;

BEGIN
OPEN c_TEMP;
LOOP
FETCH c_TEMP BULK COLLECT INTO l_data;

FORALL i IN 1..l_data.COUNT
INSERT INTO t_data VALUES l_data(i);

...
...

But this does not compile: the table t_temp mentioned in the cursor definition line does not exist at compile time and so the cursor is invalid:

PL/SQL: SQL Statement ignored
ORA-00942: Table or view does not exist

How can I overcome this problem, or is there a better way to effect this temporary extraction/reinjection of data from one table to another?

Thank you for any help you can provide.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 19 2010
Added on Dec 21 2009
13 comments
2,067 views