oracle merge 使用

create table test1(
eid number(10),
name varchar2(20),
birth date,
salary number(8,2)
);
select * from test1;

create table test2(eid number(10), name varchar2(20),birth  date,salary number(8,2));
select* from test2;

insert into test1 values (1001,'张三','20-5月-70',2300);
insert into test1 values (1002,'张三',sysdate,2300);
commit;
------------------------------------------------------------
merge into test2
using test1
on (test1.eid =test2.eid)
when matched then
update set name=test1.name,birth=test1.birth,salary=test1.salary
when not matched then
insert(eid,name,birth,salary) values (test1.eid,test1.name,test1.birth,test1.salary);
select * from test2;

 

你可能感兴趣的:(oracle)