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!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

How to use the result set of a cursor in the subquery of a delete statement

UW (Germany)May 12 2016 — edited May 13 2016

I would like to create a procedure like this: After a lot of inserts and updates driven by a cursor loop all rows in a target table have to be deleted, which are not referenced in this cursor.

Is it possible to use the result set of my cursor in the delete statement? When I try something like shown below I get "ORA-00942: Table or View does not exist".

How can I avoid to write the same complex sql statement a second time?

create procedure update_list

as

cursor c1 is

select a, b, c ...

--  here follows a complex query with several unions

;

begin

   for c1_rec in c1 loop

     -- here I do a lot of inserts in updates in a table t

   end loop;

   open c1;

   delete from table t

   where (x,y,z) not in

   (select a, b, c from c1); 

   close c1;

end;

This post has been answered by unknown-7404 on May 12 2016
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 10 2016
Added on May 12 2016
16 comments
2,972 views