Stored procedure for inserting data from one table to another in different database

时间:2017-10-12 09:58:15

标签: java oracle stored-procedures

I have pair of tables in the format MASTER TABLE and SECONDARY TABLE both in different databases. I have a dblink which connects these databases. secondary table is an empty table and both tables have same structure. Now i would like to insert all the datas of master table in one db to secondary table in another db using stored procedures. I couldnt find any posts regarding transfer of datas using different db. I am new to PL/SQL. Could somebody help me to solve this.

2 个答案:

答案 0 :(得分:0)

You can simply write a query like below:

INSERT INTO database1.dbo.mastertable(col1,col2,....)
  SELECT col1, col2,...... FROM database2.dbo.secondarytable;

答案 1 :(得分:0)

不需要存储过程。您可以通过DB Link以名称调用辅助数据库。

create or replace procedure proc_name as
begin
  insert into secondary_table@remotedb select * from primary_table;
  commit;
end;

@remotedb指的是您创建的数据库链接,以允许访问远程数据库。

编辑添加PL / SQL proc