Oracle SQL更新查询仅更新值为空的值 [英] Oracle SQL update query only update values if they are null
本文介绍了Oracle SQL更新查询仅更新值为空的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下查询,仅在它们为空时才在其中更新值.
I have the following queries where I am updating values only if they are null.
是否可以将所有这些都放在一个查询中?
Is it possible to put all of these into a single query?
UPDATE test
SET test1 = 'hello'
WHERE test1 IS NULL
和
UPDATE test
SET test2 = 'world'
WHERE test2 IS NULL
推荐答案
您可以尝试:
UPDATE test
SET test1 = NVL(test1, 'hello'),
test2 = NVL(test2, 'world')
WHERE test2 IS NULL
OR test1 IS NULL;
尽管即使对于实际上未更改的行,它也可能会触发更新触发器.
Though it may fire your update triggers even for the rows that are effectively unchanged.
这篇关于Oracle SQL更新查询仅更新值为空的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文