Skip to content Skip to sidebar Skip to footer

Dynamic Delete In Oracle

I have Some static data for that i am creating select statement with the help of union all and i am comparing those data with DB table (departments).. with the help of minus i will

Solution 1:

delete departments

  where  department_id in
         (
            select department_id

            from  (    select  department_id, department_name, manager_id,location_id 
                       from    departments

                       minus

                       (          select66,'Administration',200,1700from dual
                       unionallselect77,'Marketing'     ,201,1800from dual
                       )
                   )
         )

or

delete departments

  where  (department_id, department_name, manager_id,location_id) notin
         (          select66,'Administration',200,1700from dual
         unionallselect77,'Marketing'     ,201,1800from dual
         )

But make sure you don't have select null,null,null,null from dual among your UNION ALL records or nothing will be deleted

Solution 2:

deletes work on tables, not results of select statements. Here, you just want to delete all the records besides those with IDs 66 and 77:

DELETEFROM departments WHERE id NOTIN (66, 77)

Post a Comment for "Dynamic Delete In Oracle"