DBLINK

dblink建立跨库查询, 但是要注意clob和 blob字段不行, 解决办法是在:
1, 在源数据库做截断建视图处理 dbms_lob.substr(CHANGE_RESULT,4000,1)

2, 在目标数据库建临时表global temporary table 或者实体表

两种方法其实都不是太好, 查询速度都会受到很大影响, 最好还是定期做增量ETL吧

附部分转: http://blog.csdn.net/junfeng120125/article/details/7249321

dblink说明:

  • 查询:
    • select * from dba_db_links -- 存在哪些DBLINK
    • select * from user_sys_privs t
        where t.privilege like upper('%link%'); -- 是否有DBLINK权限
    • grant CREATE PUBLIC DATABASE LINK,DROP PUBLIC DATABASE LINK to test; -- DBLINK建立public和drop授权*
  • 创建:
    • 创建 public DBLINK的方法:
    create public database link dblink

       connect to totalplant identified by totalplant 

       using '(DESCRIPTION =

                (ADDRESS_LIST =

                  (ADDRESS = (PROTOCOL = TCP)(HOST = LOCALHOST)(PORT = 1521))

                )

                (CONNECT_DATA =

                  (SERVICE_NAME = prd.gdc)

                )

              )';
  • 语法解释:create public database link DBLINK名字(自己随便起)

             connect to 用户名 identified by 密码
    
             using '(DESCRIPTION =
    
                       (ADDRESS_LIST =
    
                         (ADDRESS = (PROTOCOL = TCP)(HOST = 要连接的数据库所在服务器的IP地址)(PORT = 1521))
    
                       )
    
                       (CONNECT_DATA =
    
                         (SERVICE_NAME = 要连接的数据库的在本地的服务名(即要连接的数据库的SID))
    
                       )
    
                     )';
    
  • 如果创建private的DBLINK

        create database link dblink

        connect to totalplant identified by totalplant 

        using '(DESCRIPTION =

                (ADDRESS_LIST =

                  (ADDRESS = (PROTOCOL = TCP)(HOST = LOCALHOST)(PORT = 1521))

                )

                (CONNECT_DATA =

                  (SERVICE_NAME = prd.gdc)

                )

              )';  
  • 查表:

    • select * from tbl_ost_notebook@dblink;
  • 删除:

    • drop public database link dblink;

    • 如果创建的是一个private的DBLINK,删除时需要用
      drop database link dblink;

你可能感兴趣的:(DBLINK)