资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

Oracle数据链创建及使用

项目上需要将老系统中的数据导入到新系统中,决定用数据链dblink将老数据导入到目标数据库中,将操作过程记录如下:

创新互联建站为您提适合企业的网站设计 让您的网站在搜索引擎具有高度排名,让您的网站具备超强的网络竞争力!结合企业自身,进行网站设计及把握,最后结合企业文化和具体宗旨等,才能创作出一份性化解决方案。从网站策划到成都做网站、成都网站制作, 我们的网页设计师为您提供的解决方案。

1.创建Dblink

  create database link ygbgtest_portaltest_link
    connect to dbuser identified by password
    using '(DESCRIPTION =
     (ADDRESS_LIST =
       (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.xx.xx)(PORT = 1521))
     )
     (CONNECT_DATA =
       (SERVICE_NAME = orcl)
     )
   )';

2.用链表查询

 执行SQL  select * from ygbgtest_portaltest_link@portal_information; 

 报错“ORA-02019:未找到远程数据库的连接说明”。检查发现表名和数据链名写反了,⊙﹏⊙,调整后执行 select * from portal_information@ygbgtest_portaltest_link;

 报错“ORA-22992:无法使用从远程表选择的LOB定位符”。检查发现报错原因是查询的源数据表中含有CLOB类型字段。 

3.解决dblink查询源数据表中含有大字段的问题

我解决该问题的方法是通过创建临时表,并将源数据表中的数据导入到临时表中。然后查询临时表以获取CLOB字段数据。

--创建临时表以获取远程表数据   
create global temporary table temp_ygbg_information on commit preserve rows 
as select * from portal_information@ygbgtest_portaltest_link;
select count(1) from temp_ygbg_information t;

 

--从临时表中将数据插入到目的表中
insert into portal_information
  (id,
   title,
   picture_url,
   status,
   author_id,
   author_name,
   create_time,
   modify_date,
   delete_date,
   view_num,
   order_flag,
   summary,
   type,
   promulgation_charge,
   information_source,
   sort_num,
   sub_title,
   is_slidenews)
 select 
   SEQ_PORTAL_INFORMATION.NEXTVAL,
   title,
   picture_url,
   status,
   author_id,
   author_name,
   create_time,
   modify_date,
   delete_date,
   view_num,
   order_flag,
   summary,
   type,
   promulgation_charge,
   information_source,
   sort_num,
   sub_title,
   is_slidenews from temp_ygbg_information t1 where t1.id=3338;

 

--查看大字段中的数据 
select dbms_lob.substr(t.summary,4000,1) ty,t.* from portal_information t where t.id=3338;

 

 

自此,通过Dblink查询和获取源数据库中的表数据并插入到目标数据库中的操作均能正常执行了。当然网上还有其它办法可以查看大字段,例如使用视图等。


网站名称:Oracle数据链创建及使用
文章网址:http://cdkjz.cn/article/iejjjh.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220