如果值已经在 table 上,则更新忽略唯一约束键。 - 甲骨文

Update ignore unique constraint key if the value is already on the table. - ORACLE

我有这个 oracle 命令。

UPDATE TABLE_NUMBERS
SET mdn = concat(concat(substr(mdn,1,2),`9`,substr(mdn,3,9))
WHERE mdn LIKE `8%` AND LENGTH(mdn)=10;

如果数字以 8 开头并且有 10 个数字,我必须将数字 9 放在第 3 个位置。

假设我有 8187412868,它将是 81987412868

但是 819874128688187412868 已经在 table 上了。

在这种情况下不需要更新或删除,但我想忽略唯一约束错误来执行整个查询。

喜欢

    if (concat(concat(subsrtr(mdn,1,2),`9`,substr(mdn,3,9))
    WHERE mdn LIKE `8%` AND LENGHT(mdn)=10)
    already on the table, then ignore
    else
    execute....

您可以使用 exists 运算符预先检查此值是否存在(另请注意,我修复了 OP 查询中的括号和拼写错误):

UPDATE table_numbers a
SET    mdn = CONCAT(CONCAT(SUBSTR(mdn, 1, 2), '9') ,SUBSTR(mdn, 3, 9))
WHERE  mdn LIKE '8%' AND 
       LENGTH(mdn) = 10 AND
       NOT EXISTS (SELECT *
                   FROM   table_numbers b
                   WHERE  a.mdn = CONCAT(CONCAT(SUBSTR(b.mdn, 1, 2), 
                                                '9'), 
                                         SUBSTR(b.mdn, 3, 9))