Ok, so basically I need to select multiple IDs from one column, then use those IDs to delete from a table.
At the moment I’m trying to do something like this but I’m not sure if I’m doing something wrong or even in the right ballpark.
--this will return multiple rows
select user_group_user_id, user_group_id
bulk collect into USERGROUPUSERID, USERGROUPID
from user_group_user_tab
where user_id = USERID; --USERID is argument passed in
--Attemting to delete multiple rows where the above results are found
delete from user_group_user_tab
where user_group_user_id in USERGROUPUSERID;
delete from user_group_tab
where user_group_id in USERGROUPID;
This is all part of a stored procedure in Oracle (11g). USERGROUPUSERID and USERGROUPID are declared earlier on.
Anyone have some suggestions on how to accomplish this? I’m not sure if that bulk collect is the way to go or if there’s a totally different approach, or if I’m just flat wrong.
Thanks!
I would normally use
i.e. just running deletes over subquery results. Temporary tables as per “ask tom” ain’t used like that in oracle, and cursor over each row would be a lot slower than simple join. On top of it I think oracle optimiser is smart enuff to cache temporary dataset ( SELECT OrderId FROM Orders WHERE CustomerName like ‘%peter%’)
Ask Tom about temp tables and cursors