gpt4 book ai didi

oracle - 使用 if 语句 PL/SQL 更新表

转载 作者:行者123 更新时间:2023-12-01 15:15:19 26 4
gpt4 key购买 nike

我正在尝试做这样的事情,但无法将其放入 oracle 编码中。

BEGIN
IF ((SELECT complete_date FROM task_table WHERE task_id = 1) IS NULL)
THEN
UPDATE task_table SET complete_date = //somedate WHERE task_id = 1;
ELSE
UPDATE task_table SET complete_date = NULL;
END IF;
END;

但这不起作用。我也试过了

IF EXISTS(SELECT complete_date FROM task_table WHERE task_id = 1)

没有运气。

最佳答案

如果您的实际逻辑与上述逻辑类似,我认为您不需要程序 block 。

假设这是你的任务:

"if the value of complete_date for id 1 is NULL, update it with XXX. Otherwise set it to null".

你可以运行...

Update task_table
set complete_date = nvl2(complete_date,NULL, <**your date**>)
where task_id = 1;

这只会用您的新日期更新 complete_date 为空的那些记录。

关于oracle - 使用 if 语句 PL/SQL 更新表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4521591/

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