【问题标题】:Oracle alternative for MySQL REPLACE INTOOracle 替代 MySQL REPLACE INTO
【发布时间】:2013-03-26 02:56:33
【问题描述】:

在 MySQL 中我们使用

REPLACE INTO

如果行不存在则插入,如果存在则更新。

Oracle中有对应的命令吗?

【问题讨论】:

标签: mysql oracle


【解决方案1】:
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

【讨论】:

【解决方案2】:

您正在 Oracle 中寻找类似 @​​987654322@ 的东西

使用

 Merge Into myTable s
   USING Select x from y;

See the documentation

【讨论】:

    猜你喜欢
    • 2019-01-21
    • 2013-03-20
    • 2010-09-05
    • 2012-08-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-21
    相关资源
    最近更新 更多