1

I've isolated my problem down to this code, which is giving me the error message "ORA-00933: SQL command not properly ended" for the on duplicate key line.

I'm trying to insert rows unless they have a duplicate key, in which case I want to update them instead. Something like insert...select and on duplicate key update.

I can see it must be a syntax problem, but I don't normally work with SQL so any help is appreciated.

insert into "tableB" ("col1", "col2")
select      "tableA"."colX", "tableA"."colY"
from        "tableA"
on duplicate key update "tableB"."col1" = "tableA"."colX";
stringy
  • 1,323
  • 7
  • 16

1 Answers1

2

I would look into using MERGE:

MERGE INTO tableB b
USING tableA a
    ON (b.col1 = a.colX)
WHEN     MATCHED THEN UPDATE SET b.col2 = a.colY
WHEN NOT MATCHED THEN INSERT( col1, col2 )
VALUES(a.colX, a.colY);

Note: this is presuming your key between the two tables is col1 and colx.

sgeddes
  • 62,311
  • 6
  • 61
  • 83