问题描述
- oracle数据库更新问题,求大神解决
-
如图,t1,t2表,我想通过t2来更新t1的name,试着写了一个
update t1 a set a.name=(select b.name from t2 b where a.id=b.id)
但这样的话,在t2中不存在的id=3的name就会成空,该怎么写呢?
解决方案
update t1 A a set name= ( select b.name from t2 B where ID = a.ID )
where exists(select t2 1 from B where ID = a.ID )
解决方案二:
select b.name from t2 b where a.id=b.id and b.name is not null.
解决方案三:
问题是。。你T2中 是存在ID =3,但是name为空的行。
还是t2中 根本就没有这一行?
解决方案四:
merge into table_1 t1
using table_2 t2
on( t1.id=t2.id )
when matched then
update name=t2.name;
时间: 2024-08-31 03:13:50