update t1 set (col1, col2,col3,...) =(select val1,val2,val3,... from t2 where t1.id=t2.id)
update t1 set (col1, col2,col3,...) =(select val1,val2,val3,... from t2 where t1.id=t2.id) where exists (select 1 from t2 where t1.id=t2.id) 存在的前提才更行
update t1 set (col1, col2,col3,...) =(select val1,val2,val3,... from t2 where t1.id=t2.id) where exists (select 1 from t2 where t1.id=t2.id) 同意这个,如果select t2会返回多行的话当然会报错
update test set id = 2, val = 'b' 等同于 update test set(id,val) = (select 2,'b' from dual)
update t1 set (col1, col2,col3,...) =(select val1,val2,val3,... from t2 where t1.id=t2.id) where exists (select 1 from t2 where t1.id=t2.id)
col2=value2,
.....
coln=valuen
where ....
set (col1, col2,col3,...) =(select val1,val2,val3,... from t2 where t1.id=t2.id)
where t1.id=1234
这样的???
我都忘记oracle pl/sql了,2年没搞了.
但保证每个t1.id和t2.id是一一对应的
set (col1, col2,col3,...) =(select val1,val2,val3,... from t2 where t1.id=t2.id)
set (col1, col2,col3,...) =(select val1,val2,val3,... from t2 where t1.id=t2.id)
where exists
(select 1 from t2 where t1.id=t2.id)
存在的前提才更行
set (col1, col2,col3,...) =(select val1,val2,val3,... from t2 where t1.id=t2.id)
where exists
(select 1 from t2 where t1.id=t2.id) 同意这个,如果select t2会返回多行的话当然会报错
update test set id = 2, val = 'b'
等同于
update test set(id,val) = (select 2,'b' from dual)
set (col1, col2,col3,...) =(select val1,val2,val3,... from t2 where t1.id=t2.id)
where exists
(select 1 from t2 where t1.id=t2.id)
只要上面的条件满足了,那个sql是可以更新多条的