Skip to content Skip to sidebar Skip to footer

Oracle Sql "deep Update"

So I'm not sure what it's called, but I need to figure out how best to do an update that may involve insert, update, and delete operations. Here's the situation: My application has

Solution 1:

MERGE is a way to go.

There is a Bag: items=Item1, Item2

There is a BagInDB: bag_id = 1 items=Item1,Item3

So we need to update Item1, add Item2 and delete Item3

1st step (join):

select*from bag fullouterjoin (select*from bagInDB where bag_id =1)

it will give you

bag_itemName bagInDb_itemName
------------ ----------------
Item1        Item1
Item2        nullnull         Item3

2nd step (merge)

merge into baginDB b
using(query above) q on b.bag_id = 1and b.itemName = q.bagInDb_itemName
when matched then
delete where q.bag_itemName isnull
<rest of the conditions>

Post a Comment for "Oracle Sql "deep Update""