用于将数据从一个表复制到另一个表的存储过程 [英] Stored Procedure for copying data from one table to another

查看:85
本文介绍了用于将数据从一个表复制到另一个表的存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在有成对的表,格式为TABLETABLE_TWIN

  • TABLE是包含大量数据的主表
  • TABLE_TWIN是一个表,具有完全相同的字段,只带有少量数据(不同的数据)
  • TABLE is the main table with lots of data
  • TABLE_TWIN is a table with the exact same fields with a little data (different data)

现在,我想使用存储过程将所有行从TABLE_TWIN复制到TABLE.我有很多这样的表,并且希望存储过程将表名作为参数,以便我可以对每个表对使用相同的过程.我不想编写 long INSERT 语句,因为这些表每个都有大约50个属性.

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.

我对PL/SQL不好,所以在这里我需要一些帮助.

I am not good with PL/SQL so I need some help here.

谢谢!

推荐答案

SQL没那么长...但是,如果您喜欢使用过程,则它是:

SQL is not so long... But if you prefer a procedure, here it is:

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;

这篇关于用于将数据从一个表复制到另一个表的存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆