8

In MySQL we use

REPLACE INTO

to insert if a row doesn't exist and to update if it exists.

Is there a corresponding command in Oracle?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Jiby Jose
  • 3,745
  • 4
  • 24
  • 32

2 Answers2

9
MERGE
INTO    destTable d
USING   (
        SELECT  *
        FROM    sourceTable
        ) s
ON      (s.id = d.id)
WHEN NOT MATCHED THEN
INSERT  (id, destCol1, destCol2)
VALUES  (id, sourceCol1, sourceCol2)
WHEN MATCHED THEN
UPDATE
SET     destCol1 = sourceCol1,
        destCol2 = sourceCol2
Quassnoi
  • 413,100
  • 91
  • 616
  • 614
0

You are looking for something like Merge in Oracle

Use

 Merge Into myTable s
   USING Select x from y;

See the documentation

Scotch
  • 3,186
  • 11
  • 35
  • 50