用可能为空值更新非空字段
在下面的查询中:
update collect_irc_deploy c
set hid = (select id
from auth_hierarchy
where fqdn = (select location
from reserve
where id=c.rid
)
)
where hid = 0 and rid is not null
子查询 select id from auth_hierarchy where fqdn = (select location from Reserve where id = c.rid)
可能返回 NULL
而字段 hid
是NOT NULL
。
如何修改语句,以便在子查询返回 NULL 时跳过该数据项,而不是使整个执行失败?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 update...join 语法来确保仅更新连接的行:
You can use update...join syntax to ensure only joined rows are updated:
使用
UPDATE IGNORE
解决了我的问题。但它会生成警告消息。Use
UPDATE IGNORE
solved my problem. But it will generate warning messages.