oracle 将数据从一张表复制到另一张表的存储过程
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1842672/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Stored Procedure for copying data from one table to another
提问by Virat Kadaru
I have pairs of tablesin the format TABLE
and TABLE_TWIN
now
我有成对的表格格式TABLE
,TABLE_TWIN
现在
TABLE
is the main table with lots of dataTABLE_TWIN
is a table with the exact same fields with a little data (different data)
TABLE
是包含大量数据的主表TABLE_TWIN
是具有完全相同字段和少量数据(不同数据)的表
Now I would like to copy all rows from TABLE_TWIN
to TABLE
using a stored procedure. I have many such tables and could like the stored procedure to take the table name(s) as parameter(s) so that I can use the same procedure for each table pair. I do not want to write long INSERT
statements because these tables have around 50 attributes each.
现在我想使用存储过程将所有行复制TABLE_TWIN
到TABLE
。我有很多这样的表,并且可能希望存储过程将表名作为参数,以便我可以对每个表对使用相同的过程。我不想写长INSERT
语句,因为这些表每个都有大约 50 个属性。
I am not good with PL/SQL so I need some help here.
我不擅长 PL/SQL,所以我需要一些帮助。
Thanks!
谢谢!
回答by Egor Rogov
SQL is not so long... But if you prefer a procedure, here it is:
SQL 并没有那么长......但是如果你更喜欢一个过程,这里是:
create or replace procedure table_copy(
p_tab_from varchar2,
p_tab_to varchar2)
is
begin
execute immediate 'insert into '||p_tab_to||' (select * from '||p_tab_from||')';
end;
回答by Klaus Byskov Pedersen
insert into table_twin (select * from table)
should do it
应该做