Oracle跨数据导入数据实现

Step1: 创建与之相连的数据链接

create database link LINK_NAME connect to USERNAME identified by PASSWORD using 'SID[_SERVERNAME]';
比如:create database link MYLINK connect to test identified by 1234 using 'TEST'; 是用test/1234创建一个连接到Test数据库的连接,命名为MYLINK,下面用到。
Step2: 查询被连接数据的表
select * from TABLE_NAME@LINK_NAME where xxx
比如:select * from users@MYLINK; 是查询Test数据库中users表的所有内容。
Ste3: 将查询结果插入到当前数据中相同结构的表
insert into TABLE_NAME select * from TABLE_NAME@LINK_NAME where xxx
比如:insert into users select * from users@MYLINK where xxx; 将Test数据库中users表符合条件的记录插入到当前数据中的users表。
Step4: 最后别忘了commit

Leave a Reply


提醒: 评论者允许使用'@user空格'的方式将自己的评论通知另外评论者。例如, ABC是本文的评论者之一,则使用'@ABC '(不包括单引号)将会自动将您的评论发送给ABC。请务必注意user必须和评论者名相匹配(大小写一致)。