首页 > 代码库 > PLSQL_Database Link的基本概念和用法(概念)

PLSQL_Database Link的基本概念和用法(概念)

2014-06-08 BaoXinjian

一、总结


1. 建立数据库连接的方式

2. 查询方式

3. 连接类型

4. 常用的查询

 

二、具体分析


1. 建立数据库连接的方式

    (1).使用tns进行建立

                CREATE DATABASE LINK linkname

                    CONNECT TO user_name IDENTIFIED BY password

                    USING tns_dbname 

    (2).直接建立

                CREATE DATABASE LINK linkname

                     CONNECT TO user_nameIDENTIFIED BY password

                    USING ‘(DESCRIPTION =

                                           (ADDRESS_LIST =

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

                                            )

                                            (CONNECT_DATA =http://www.mamicode.com/

                                                    (SERVICE_NAME = dbname)

                                            )

                                 )‘    

 

2. 查询方式

    (1).直接使用select * form tablename@dblink    

    (2).建立同义词,按同义词方式进行查询

    (3).建立物化视图,提高执行效率

        create public synonym syn_name for tablename@linknam

 

3. 连接类型

    (1).私有Private

    (2).共有Public

        建立共有的数据库连接时必须是有sysadmin和sys账户

                CREATE PUBLIC DATABASE LINK linkname

                    CONNECT TO user_name IDENTIFIED BY password

                    USING tns_dbname

 

4. 常用的查询

    (1).查询当前账户所有的dblink连接

                select * from user_db_links; 

    (2).查询当前系统所有的dblink连接

                select * from dba_db_links  

    (3).查询当前正在连接的dblink连接

                select * from v$dblink

 

Thanks and Regards