日期:2014-05-17 浏览次数:20973 次
--Table1 ID NAME AGE 1 小明 18 2 小張 20 3 小王 22 --Table2 ID NAME AGE 001 小明 002 小王 003 小張 18
ID NAME AGE
1 小明 18
2 小張 20
3 小王 22
--Table2
ID NAME AGE
001 小明
002 小王
003 小張 18
drop table t2;
create table t1(
id int,
name varchar2(20),
age int
);
create table t2(
id int,
name varchar2(20),
age int
);
insert into t1 values (1,'小明',18);
insert into t1 values (2,'小張',20);
insert into t1 values (3,'小王',22);
insert into t2 values (1,'小明',null);
insert into t2 values (2,'小王',null);
insert into t2 values (3,'小張',18);
commit;
update t2
set t2.age = (select t1.age
from t1
where t1.name = t2.name
and rownum = 1)
where exists (select 1 from t1 where t1.name = t2.name);
commit;
select * from t2;
ID NAME AGE
--------------------------------------- -------------------- ---------------------------------------
1 小明 18
2 小王 22
3 小張 20