gpt4 book ai didi

sql - Oracle 中的条件更新语句

转载 作者:行者123 更新时间:2023-12-04 21:34:16 24 4
gpt4 key购买 nike

我在 中构建条件更新语句时遇到问题甲骨文 .为了便于理解,我将简化问题,基本上我的更新语句应如下所示:

UPDATE SAMPLE_TAB1 t 
SET t.sample_column1 =NVL(t.sample_column1, **SOME LOGIC**);
***SOME LOGIC***部分应如下所示:(请考虑这只是一个伪代码)
IF ((SELECT sample_column2 FROM SAMPLE_TAB2 
WHERE sample_column2= sample_value2
AND sample_column3 = sample_value3 )='FALSE' THEN
t.sample_column1 =0;
ELSE

t.sample_column1 =(SELECT sample_column1 FROM SAMPLE_TAB3
WHERE sample_column4= sample_value4
AND sample_column5 = sample_value5 )

END IF;

欢迎对这个问题提出任何想法。谢谢你。

最佳答案

试试下面的代码

UPDATE SAMPLE_TAB1 t 
SET t.sample_column1 = (
case when ((SELECT sample_column2 FROM SAMPLE_TAB2
WHERE sample_column2= sample_value2
AND sample_column3 = sample_value3 ) = 'FALSE' )
then 0
else
(SELECT sample_column1 FROM SAMPLE_TAB3
WHERE sample_column4= sample_value4
AND sample_column5 = sample_value5 )
end

)
WHERE t.sample_column1 is not null;

关于sql - Oracle 中的条件更新语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18536818/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com