首页 > 其他 > 详细

merge的用法

时间:2014-09-11 08:45:42      阅读:309      评论:0      收藏:0      [点我收藏+]

create table t1(
    sid integer,
    sname varchar2(32),
    
);
alter table t1 modify gender varchar2(3);
alter table t1 modify sname varchar2(30);

create table t2(
    sid integer,
    sname varchar2(32)
);

alter table t1 rename column sid to dsi;

insert into t1 values(1,‘hello_what‘);
insert into t1 values(2,‘hi‘);

insert into t2 values(1,‘hello‘);
commit;

select * from t1;
select * from t2;

merge into t2
using (select * from t1) t1
on (t1.dsi = t2.sid)
when matched then update set t2.sname = t1.sname
  delete  where t2.sid = 1
when not matched then insert (sid,sname) values(t1.dsi,t1.sname)

merge的用法

原文:http://www.cnblogs.com/zuo-zijing/p/3965609.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!