create table t_emp (
id number(4),
name varchar2(12),
password varchar2(12)
)
insert into t_emp values(4,'demo','1454');
select * from t_emp
truncate table t_emp_back
select * from t_emp_back
drop table t_emp
create table t_emp as select * from t_emp_back
--创建存储过程
create or replace procedure test_pro
is
begin
/*
插入数据:当数据不存在的时候则插入数据,存在这更新
*/
merge into t_emp_back b --插入备份表
using (
--原有的表中的数据与备份表做差集
select id,name,password from t_emp
minus
select id,name,password from t_emp_back)mu --备份表
on( b.id = mu.id) --条件
when matched then --数据存在,则更新
update set
b.name = mu.name,
b.password = mu.password
when not matched then --数据不存在则插入
insert (id,name,password)
values(mu.id,mu.name,mu.password) ;
end;
--调用存储过程
begin
test_pro;
end;
select * from t_emp
select id,name,password from t_emp
minus
select id,name,password from t_emp_back mu