使用 if 语句 PL/SQL 更新表
我正在尝试做这样的事情,但在将其放入 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)
但没有运气。
I am trying to do something like this but am having trouble putting it into oracle coding.
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;
But this does not work. I also tried
IF EXISTS(SELECT complete_date FROM task_table WHERE task_id = 1)
with no luck.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您的实际逻辑与上面的逻辑类似,我认为您不需要程序块。
假设这是您的任务:
您可以运行 ...
这只会用您的新日期更新complete_date 为 null 的记录。
I don't think you'd need the procedural block if your actual logic is like the one above.
Assuming this is your task:
You could just run ...
This will only update those records where the complete_date is null with your new date.
这部分的目的是什么?
是查找是否存在complete_date为null且task_id = 1的行?
或者是检查是否没有task_id = 1的行?
What is the intention of this part?
Is it to find if there are rows where complete_date is null and task_id = 1?
Or is it to check if there are no rows where task_id = 1?