A cursor with a select on a table that does not exist (yet)
631752Dec 21 2009 — edited Dec 22 2009Hi,
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.