首页 > 代码库 > merge的用法

merge的用法

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的用法