create table t1 (
id number primary key,
name varchar(30),
count number
);
create table t2 (
id number primary key,
name varchar(30),
count number
);
--创建一个复制数据的存储过程,根据表1的记录id,复制该记录到表2
create or replace procedure copy_test(
ID in t1.id%type
)is
t1_id t1.id%type;
t1_name t1.name%type;
t1_count t1.count%type;
begin
t1_id := ID;
select t1.name , t1.count into t1_name,t1_count from t1 where t1.id = t1_id;
insert into t2 values(t1_id,t1_name,t1_count);
commit;
end;
insert into t1 values(1,'aaa',6); --给t1添加一条数据
call copy_test(1); --调用存储过程
insert into t1 values(5,'AAA',6); --给t1添加一条数据
call copy_test(5); --调用存储过程
然后你会发现t2里面有了相同的数据。