Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle alternative for MySQL REPLACE INTO

Tags:

mysql

oracle

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?

like image 981
Jiby Jose Avatar asked Apr 04 '13 06:04

Jiby Jose


People also ask

Which one is correct for replace into in MySQL?

Don't use REPLACE INTO in MySQL, rather use INSERT ...

Is Oracle similar to MySQL?

MySQL and Oracle SQL are both RDBMSs (relational database management systems) owned by Oracle Corporation. MySQL is built to be primarily free and open-source, while Oracle is primarily built to be commercial and paid. MySQL is also more customizable than Oracle which is because Oracle is a finished product.

Which is best between MySQL and Oracle?

In terms of software, Oracle is the more powerful one because of its extra features over the basic MySQL. It also supports parallel and distributed Databases and offers better indexing because of which can have a competitive advantage over MySQL.

Is Oracle similar to SQL?

Oracle, meanwhile, uses PL/SQL, or Procedural Language/SQL. Both are different “flavors” or dialects of SQL and both languages have different syntax and capabilities. The main difference between the two languages is how they handle variables, stored procedures, and built-in functions.


1 Answers

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
like image 156
Quassnoi Avatar answered Oct 04 '22 06:10

Quassnoi