我Oracle基础很差,可不可以写的再准确,再明白一点,最后帮忙解释一下。我没大看懂。 exists(select 1 from from a where a.id=b.id) 这个1是什么意思?我要把b表中所有记录都更新了。 谢谢!!
update b set memo = ( select a.name from a where a.id = b.id) 是这样吗?
exists(select 1 from a where a.id=b.id) 是判断如果 a中存在 a.id=b.id 有返回结果,则执行前面的语句,duanzilin(寻) 的 update b set memo = ( select a.name from a where a.id = b.id) 应该就是你要的结果吧!
update b set memo = ( select a.name from a where a.id = b.id) 直接这么写是错误的,导致的结果是,如果a表中找不到对应的b表id ,那么你将犯下致命错误,那就是A表中如果无B表中对应的ID,那么所有的b表中MEMO将被设置成空,这是你需要的吗?所以必须加上 where exists (select 2 from a where a.id=b.id ) (意思是只更新在A表中存在的数据) SELECT 1, SELECT 2 FROM ......是1还有2无所谓,只是随便找个结果看交集有结果没有而已,你自己随便写3都可以
exists(select 1 from from a where a.id=b.id)
这个1是什么意思?我要把b表中所有记录都更新了。
谢谢!!
是这样吗?
直接这么写是错误的,导致的结果是,如果a表中找不到对应的b表id ,那么你将犯下致命错误,那就是A表中如果无B表中对应的ID,那么所有的b表中MEMO将被设置成空,这是你需要的吗?所以必须加上
where exists (select 2 from a where a.id=b.id ) (意思是只更新在A表中存在的数据) SELECT 1, SELECT 2 FROM ......是1还有2无所谓,只是随便找个结果看交集有结果没有而已,你自己随便写3都可以