注册 登录
编程论坛 Oracle论坛

有个问题,求大佬帮忙

w972312 发布于 2018-11-26 22:49, 5850 次点击

现在有2张表
author字段是 title 和 author
只有本站会员才能查看附件,请 登录

holding
字段是 barcode和 callno
只有本站会员才能查看附件,请 登录

现在是想查询author表的title和holding表中的barcode字段相同的值,然后。将author中auth的值,添加到holding中的callno
这是我写的 update holding h set h.CALLNO = (select a.AUTH from AUTHOR a where a.TITLE=h.BARCODE),这条语句错误了,他把我holding中callno全部变成null
2 回复
#2
pracy872018-11-30 21:19
update  holding  h  set h.callno=(select a.AUTH from AUTHOR a where a.TITLE=h.BARCODE) where exists(select 1 from AUTHOR a where a.TITLE=h.BARCODE);
你原来的写法,没有去框定范围,如果callno在AUTHOR 表中不存在,就会更新所有的数据为空,需要指定范围
#3
Binhun2019-06-04 14:54
1