earngreen
asked on
Cursor with multiple inserts
l_sOwner VARCHAR2(30);I need to insert into multiple tables reusing the same cursor and wondered if anyone could provide the best approach something similar to this. I am unable to use temporary tables.
l_sName VARCHAR2(30);
l_sType VARCHAR2(19);
CURSOR cur IS SELECT owner, object_name name, object_type type FROM all_objects;
BEGIN
dbms_output.put_line('Befo
OPEN cur;
dbms_output.put_line('Befo
LOOP
FETCH cur INTO l_sOwner, l_sName, l_sType;
IF cur%NOTFOUND THEN
EXIT;
END IF;
INSERT INTO temp values (l_sOwner, l_sName, l_sType);
END LOOP;
LOOP
FETCH cur INTO l_sOwner, l_sName, l_sType;
IF cur%NOTFOUND THEN
EXIT;
END IF;
INSERT INTO temp22 values (l_sOwner, l_sName, l_sType);
END LOOP;
LOOP
FETCH cur INTO l_sOwner, l_sName, l_sType;
IF cur%NOTFOUND THEN
EXIT;
END IF;
INSERT INTO temp33 values (l_sOwner, l_sName, l_sType);
END LOOP;
CLOSE cur;
dbms_output.put_line('Afte
COMMIT;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Did you actually get an answer to your previous question or did you just accept the last post to get around the new question lock?
or use a single multi-table insert
INSERT ALL
INTO temp
VALUES (owner, object_name, object_type)
INTO temp22
VALUES (owner, object_name, object_type)
INTO temp33
VALUES (owner, object_name, object_type)
SELECT owner, object_name, object_type FROM all_objects
INSERT ALL
INTO temp
VALUES (owner, object_name, object_type)
INTO temp22
VALUES (owner, object_name, object_type)
INTO temp33
VALUES (owner, object_name, object_type)
SELECT owner, object_name, object_type FROM all_objects
ASKER
slightwv,
I had to use the merge for something else and it worked great. So I answered the question with the solution used
I had to use the merge for something else and it worked great. So I answered the question with the solution used
ASKER
That worked. Thx
just curious, did you try the multi-table insert? It should be much more efficient since it's one sql instead of
1 + 3 * numrows
and eliminated sql to pl/sql context switches
1 + 3 * numrows
and eliminated sql to pl/sql context switches