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,030
  • 21
  • 100
  • 124
Jiby Jose
  • 3,390
  • 4
  • 23
  • 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
  • 398,504
  • 89
  • 603
  • 604
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,080
  • 11
  • 33
  • 48