日期:2014-05-17  浏览次数:20852 次

求助Oracle語句,答案正確馬上結貼
SQL code

--TABLE1
ID NAME AGE
1 小張 18
2 小王 20
3 小明 22

--TABLE2
ID NAME AGE
001 小王 18
002 小明 20
003 小明
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: 單行子查詢返回多于一個行