0

I would like to update a table (Oracle) from the results of another (too long and complex) query.

For simplicity, Query1 is my complex query and returns something like this:

 Item_ID | Item_Data
 --------------------
 10          XXX
 20          ZZZZ
 30          SSSS

i want to do this

 UPDATE MyTable SET MyTable.MyData = Query1.Item_Data where MyTable.MyID = Query1.Item_ID

How can i achieve this? Thanks

1 Answer 1

2

Check the MERGE INTO clause. I can't test this right now but it should be something like this:

MERGE INTO mytable mt
USING (your complex query here) cc
  ON mt.myid = cc.item_id
WHEN MATCHED THEN UPDATE SET mt.mydata = cc.item_data
3
  • unfortunaetly i am getting this error: [Mercury][Oracle JDBC Driver][Oracle]ORA-29886: feature not supported for domain indexes
    – Achraf
    Oct 6, 2011 at 14:59
  • From what I've read, that's a limitation with tables that contain domain indexes. Another option would be an UPDATE of the type 'UPDATE mytable mt SET mydata = (SELECT itemdata FROM (complex query here) WHERE item_id = my.myid)'.
    – Mike
    Oct 6, 2011 at 15:52
  • Thanks, this seems to work, although it is VERY slow. i think i will have to go to do it programatically with a for loop
    – Achraf
    Oct 6, 2011 at 16:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.