日期:2014-05-17 浏览次数:21010 次
create table tb1(id int,chanpin varchar(20),money number);
create table tb2(id int,chanpin varchar(20));
insert into tb1 values(01,'手机',200);
insert into tb1 values(02,'电冰箱',500);
insert into tb1 values(03,'手机',300);
insert into tb2 values(01,'手机A');
insert into tb2 values(02,'电冰箱B');
select * from tb1;
select * from tb2;
--第一种方法
update tb1 a1 set chanpin=(select chanpin from tb2 a2 where a1.id=a2.id)
where exists (select 'x' from tb2 a2 where a1.id=a2.id);
rollback;
--第二种
merge into tb1 a1 using tb2 a2 on (a1.id=a2.id)
when matched then update set a1.chanpin=a2.chanpin;
rollback;