sql 两张表之间传递数据

两张SQL表 表1 和表2 字段完全相同全是 id 姓名 基数
现想将表1中ID=5的这一条数据复制到表2中
求语句 在线等!!

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里面有了相同的数据。

温馨提示:答案为网友推荐,仅供参考
第1个回答  2015-11-26
insert into 表2(id,姓名,基数) select id,姓名,基数 from 表1 where id=5
第2个回答  2015-11-26
insert into 表2 select * from 表1 where ID=5本回答被提问者采纳
相似回答