当前位置: 代码迷 >> Oracle管理 >> Oracle語句,答案正確馬上結貼
  详细解决方案

Oracle語句,答案正確馬上結貼

热度:78   发布时间:2016-04-24 05:20:44.0
求助Oracle語句,答案正確馬上結貼
SQL code
--TABLE1ID NAME AGE1 小張 182 小王 203 小明 22--TABLE2ID NAME AGE001 小王 18002 小明 20003 小明004 小張 22

表結構應該是這樣的,TABLE1的NAME不會重複,而TABLE2的NAME會重複,要根據TABLE1和TABLE2的NAME把TABLE1的AGE賦到TABLE2對應的AGE上..最好有2種做法...

------解决方案--------------------
update table2 tt
set tt.age = (select v.age
from (select t1.id,
t1.name,
(select t.age
from table1 t
where t.name = t1.name) age
from table2 t1) v
where v.id = tt.id)
不知道是否可以,数据量大的话,这样的更新感觉会比较耗时
------解决方案--------------------
2种写法???
来个update 来个merge么 哈哈
------解决方案--------------------
Have a try.[code=SQL]
update table2
set table2.age =
(select table1.age from table1 where table1.name = table2.name);code]
------解决方案--------------------
探讨
引用:

代码如下:
SQL code
update table2
set table2.age =
(select table1.age from table1 where table1.name = table2.name);

你的报错: ORA-01427: 單行子查詢返回多于一個行
  相关解决方案