用oracle存储过程将一张表的数据查出插入另一张表
1、创建测试表,
create table test_tbl_1(id number, value varchar2(20));
create table test_tbl_2(id number, value varchar2(20));
2、先向table1中插入测试数据;
insert into test_tbl_1 select level, 'lvl_'||level from dual connect by level<=10;
commit;
3、查询table1表中全量数据;select t.*, rowid from test_tbl_1 t;
4、编写存储过程,将table1表数据插入table2表;
create or replace procedure sp_test_insert
as
begin
insert into test_tbl_2 select * from test_tbl_1;
commit;
end;
5、查看table2表中全量数据;可以发现table1表中数据已经插入table2表中;
select t.*, rowid from test_tbl_2 t;
create or replace procedure test
is
begin
--两个表字段一样
insert into 表名1 select * from 表名2;
--字段不一样
insert into 表名1(字段1,字段2,字段3) select 字段1,字段2,字段3 from 表名2;
COMMIT;
end
insert into table2(字段1,字段2,字段3) select 字段1,字段2,字段3 from table1;
commit;
把字段名称对应好就OK啊