oracle create database link_資料庫連結測試
附錄:
http://czmmiao.iteye.com/blog/1236562 --網上關於db link講解
http://czmmiao.iteye.com/blog/1236562 --網上關於db link講解
----建立db link語法
CREATE [ SHARED ] [ PUBLIC ] DATABASE LINK dblink
[ CONNECT TO
{ CURRENT_USER
| user IDENTIFIED BY password [ dblink_authentication ]
}
| dblink_authentication
]...
[ USING connect_string ] ;
CREATE [ SHARED ] [ PUBLIC ] DATABASE LINK dblink
[ CONNECT TO
{ CURRENT_USER
| user IDENTIFIED BY password [ dblink_authentication ]
}
| dblink_authentication
]...
[ USING connect_string ] ;
----如下為db link子句的語義
---如下子句必須與shared子句搭配使用
dblink_authentication
---如下子句必須與shared子句搭配使用
dblink_authentication
You can specify this clause only if you are creating a shared database link—that is,
you have specified the SHARED clause. Specify the username and password on the target instance.
This clause authenticates the user to the remote server and is required for security.
The specified username and password must be a valid username and password on the remote instance.
The username and password are used only for authentication. No other operations are performed on behalf of this user.
you have specified the SHARED clause. Specify the username and password on the target instance.
This clause authenticates the user to the remote server and is required for security.
The specified username and password must be a valid username and password on the remote instance.
The username and password are used only for authentication. No other operations are performed on behalf of this user.
---如下子句
SHARED
--如指此子句建立基於單一網路連線(自源庫到目標庫)的db link,如此多個會話可以共享此db link,有點像shared server mode
Specify SHARED to create a database link that can be shared by multiple sessions using a single
network connection from the source database to the target database. In a shared server configuration,
----這種模式,一直保持一定資料的連線到目標庫,防止過多的連線產生.但是,如多個客戶端訪問相同的本地模式物件時,共享的私有資料庫連線非常在用
---因此使用相同的私有資料庫連線
shared database links can keep the number of connections into the remote database from becoming too large.
Shared links are typically also public database links. However, a shared private database link can be useful
when many clients access the same local schema, and therefore use the same private database link.
--這種模式,源庫的多個會話共享到目標庫相同連線,即一個源庫連線到目標庫,另一個源庫連線則斷開;
In a shared database link, multiple sessions in the source database share the same connection to the target database.
Once a session is established on the target database, that session is disassociated from the connection, to make the
connection available to another session on the source database. To prevent an unauthorized session from attempting to
---為了防止非授權連線到目標庫,你必須指定dblink_authentication僅允許授權使用者訪問目標庫
connect through the database link, when you specify SHARED you must also specify the dblink_authentication clause for
the users authorized to use the database link.
SHARED
--如指此子句建立基於單一網路連線(自源庫到目標庫)的db link,如此多個會話可以共享此db link,有點像shared server mode
Specify SHARED to create a database link that can be shared by multiple sessions using a single
network connection from the source database to the target database. In a shared server configuration,
----這種模式,一直保持一定資料的連線到目標庫,防止過多的連線產生.但是,如多個客戶端訪問相同的本地模式物件時,共享的私有資料庫連線非常在用
---因此使用相同的私有資料庫連線
shared database links can keep the number of connections into the remote database from becoming too large.
Shared links are typically also public database links. However, a shared private database link can be useful
when many clients access the same local schema, and therefore use the same private database link.
--這種模式,源庫的多個會話共享到目標庫相同連線,即一個源庫連線到目標庫,另一個源庫連線則斷開;
In a shared database link, multiple sessions in the source database share the same connection to the target database.
Once a session is established on the target database, that session is disassociated from the connection, to make the
connection available to another session on the source database. To prevent an unauthorized session from attempting to
---為了防止非授權連線到目標庫,你必須指定dblink_authentication僅允許授權使用者訪問目標庫
connect through the database link, when you specify SHARED you must also specify the dblink_authentication clause for
the users authorized to use the database link.
---建立資料庫連結
SQL> create database link dlink1 connect to scott identified by system using 'orcl';
SQL> create database link dlink1 connect to scott identified by system using 'orcl';
Database link created
--查詢資料庫連結資訊
SQL> desc user_db_links;
Name Type Nullable Default Comments
-------- -------------- -------- ------- ----------------------------------
DB_LINK VARCHAR2(128) Name of the database link
USERNAME VARCHAR2(30) Y Name of user to log on as
PASSWORD VARCHAR2(30) Y Deprecated-Password for logon
HOST VARCHAR2(2000) Y SQL*Net string for connect
CREATED DATE Creation time of the database link
SQL> desc user_db_links;
Name Type Nullable Default Comments
-------- -------------- -------- ------- ----------------------------------
DB_LINK VARCHAR2(128) Name of the database link
USERNAME VARCHAR2(30) Y Name of user to log on as
PASSWORD VARCHAR2(30) Y Deprecated-Password for logon
HOST VARCHAR2(2000) Y SQL*Net string for connect
CREATED DATE Creation time of the database link
SQL> select * from user_db_links;
DB_LINK USERNAME PASSWORD HOST CREATED
-------------------------------------------------------------------- -----------
DLINK1 SCOTT orcl 2013/1/25 1
-------------------------------------------------------------------- -----------
DLINK1 SCOTT orcl 2013/1/25 1
SQL> select * from tab where rownum<=5;
TNAME TABTYPE CLUSTERID
------------------------------ ------- ----------
BASE_BILL TABLE
BIN$NDy5NJ6AQ/C7STM+t8OG5A==$0 TABLE
BIN$aJswa+ULQ22uo7ykPIg6Vw==$0 TABLE
BIN$wEmpOM9LQValskI1dzyrqg==$0 TABLE
CLUSTER1 CLUSTER
------------------------------ ------- ----------
BASE_BILL TABLE
BIN$NDy5NJ6AQ/C7STM+t8OG5A==$0 TABLE
BIN$aJswa+ULQ22uo7ykPIg6Vw==$0 TABLE
BIN$wEmpOM9LQValskI1dzyrqg==$0 TABLE
CLUSTER1 CLUSTER
---測試資料庫連結是否正常
SQL> select * from where rownum<=2; --可查詢結果
SQL> select * from where rownum<=2; --可查詢結果
---儲存過程中測試資料庫連結
SQL> create or replace procedure proc_database_link
2 as
3 v_link varchar2(1000);
4 begin
5 select bill_name into v_link from where rownum=1;
6 dbms_output.put_line(v_link);
SQL> create or replace procedure proc_database_link
2 as
3 v_link varchar2(1000);
4 begin
5 select bill_name into v_link from where rownum=1;
6 dbms_output.put_line(v_link);
PL/SQL procedure successfully completed
SQL> create table t_tb(a varchar2(1000));
---連線到另一個system使用者
SQL> conn
Connected to Oracle Database 11g Enterprise Edition Release 11.2.0.1.0
Connected as
SQL> show user
User is "system"
---在scott使用者建立的database link在system使用者不可用,即create database link建立的資料庫連結僅建立使用者可用
SQL> select bill_name from where rownum=1;
User is "system"
---在scott使用者建立的database link在system使用者不可用,即create database link建立的資料庫連結僅建立使用者可用
SQL> select bill_name from where rownum=1;
select bill_name from where rownum=1
ORA-02019: connection description for remote database not found
---重連scott使用者
SQL> conn
Connected to Oracle Database 11g Enterprise Edition Release 11.2.0.1.0
Connected as
---刪除dlink1資料庫連結
SQL> drop database link dlink1;
SQL> drop database link dlink1;
Database link dropped
SQL>
SQL>
---建立公共資料庫連結,所謂即庫所有使用者皆可使用此資料庫連結
SQL> create public database link dlink1 connect to scott identified by system using 'orcl';
SQL>
---建立公共資料庫連結,所謂即庫所有使用者皆可使用此資料庫連結
SQL> create public database link dlink1 connect to scott identified by system using 'orcl';
Database link created
SQL> show user
User is "scott"
---當前建立使用者可用
SQL> select bill_name from where rownum=1;
User is "scott"
---當前建立使用者可用
SQL> select bill_name from where rownum=1;
BILL_NAME
--------------------------------------------------------------------------------
1
---再次連線到system使用者
SQL> conn
Connected to Oracle Database 11g Enterprise Edition Release 11.2.0.1.0
Connected as
---system使用者也可用
SQL> select bill_name from where rownum=1;
--------------------------------------------------------------------------------
1
---再次連線到system使用者
SQL> conn
Connected to Oracle Database 11g Enterprise Edition Release 11.2.0.1.0
Connected as
---system使用者也可用
SQL> select bill_name from where rownum=1;
BILL_NAME
--------------------------------------------------------------------------------
1
--------------------------------------------------------------------------------
1
SQL>
---私有與公共database link的區別
-----公共(注:公共owner是public)
SQL> select * from dba_db_links;
SQL> select * from dba_db_links;
OWNER
----------
PUBLIC
----------
PUBLIC
---私有 (注:私有owner是建立database link的使用者)
SQL> select * from dba_db_links;
SQL> select * from dba_db_links;
OWNER
---------
SCOTT
---------
SCOTT
---current_user建立的db link
SQL> create database link dlink1 connect to current_user;
SQL> create database link dlink1 connect to current_user;
Database link created
SQL> desc T_A;
Name Type Nullable Default Comments
---- ------------- -------- ------- --------
A VARCHAR2(100) Y
Name Type Nullable Default Comments
---- ------------- -------- ------- --------
A VARCHAR2(100) Y
--執行報如下錯誤
SQL> select * from where rownum=1;
SQL> select * from where rownum=1;
select * from where rownum=1
ORA-02019: connection description for remote database not found
---如下2引數控制一個引數或會話可以同時最大開啟的db link數量
SQL> show parameter open_link
SQL> show parameter open_link
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
open_links integer 4
open_links_per_instance integer 4
------------------------------------ ----------- ------------------------------
open_links integer 4
open_links_per_instance integer 4
---連續建立5個db link
SQL> create public database link dlink1 connect to scott identified by system using 'orcl';
SQL> create public database link dlink1 connect to scott identified by system using 'orcl';
Database link created
SQL>
SQL> create public database link dlink2 connect to scott identified by system using 'orcl';
SQL> create public database link dlink2 connect to scott identified by system using 'orcl';
Database link created
SQL> create public database link dlink3 connect to scott identified by system using 'orcl';
Database link created
SQL> create public database link dlink4 connect to scott identified by system using 'orcl';
Database link created
SQL> create public database link dlink5 connect to scott identified by system using 'orcl';
Database link created
SQL> desc t_a;
Name Type Nullable Default Comments
---- ------------- -------- ------- --------
A VARCHAR2(100) Y
Name Type Nullable Default Comments
---- ------------- -------- ------- --------
A VARCHAR2(100) Y
SQL> update set a=10 where rownum=1;
1 row updated
SQL> update set a=10 where rownum=1;
1 row updated
SQL> update set a=10 where rownum=1;
1 row updated
SQL> update set a=10 where rownum=1;
1 row updated
---當開啟第5個db link報錯
SQL> update set a=10 where rownum=1;
SQL> update set a=10 where rownum=1;
update set a=10 where rownum=1
ORA-02020: too many database links in use
---如不指定connect to identified by 則the database link uses the user name and password of each user who is connected to the database.
-----This is called a connected user database link. 即連線到遠端庫的每一個使用者的使用者名稱和密碼嘗試進行連線
SQL> create public database link dlink6 using 'orcl';
Database link created
SQL> rollback;
Rollback complete
SQL> select * from where rownum=1;
A
--------------------------------------------------------------------------------
10
--------------------------------------------------------------------------------
10
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28211342/viewspace-2135690/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- PostgreSQL:資料庫連結測試SQL資料庫
- java Jdbc連線oracle資料庫連線測試JavaJDBCOracle資料庫
- 資料庫連結(database link)小結資料庫Database
- 2.4.1 使用 CREATE DATABASE 子句建立資料庫Database資料庫
- 2.4 使用 CREATE DATABASE 語句建立資料庫Database資料庫
- 4、MySQL建立資料庫(CREATE DATABASE語句)MySql資料庫Database
- python連線資料庫測試Python資料庫
- Oracle 閃回資料庫測試Oracle資料庫
- oracle測試資料庫啟用Oracle資料庫
- 深圳軟體測試學習:【資料庫】-【oracle】-連線查詢資料庫Oracle
- database資料庫的資料結構Database資料庫資料結構
- oracle之 oracle database vault(資料庫保險庫)OracleDatabase資料庫
- 部落格連結—Oracle資料庫類Oracle資料庫
- C#測試資料庫連線是否成功C#資料庫
- 【JDBC】java連線池模擬測試連線Oracle資料庫指令碼參考JDBCJavaOracle資料庫指令碼
- python環境連結Oracle資料庫PythonOracle資料庫
- 通過Java程式測試資料庫連線資訊Java資料庫
- CDH 5.13 hue資料庫連線測試失敗資料庫
- Oracle——04同義詞與資料庫連結Oracle資料庫
- perl 資料庫連結失敗重試機制資料庫
- 大資料測試與 傳統資料庫測試大資料資料庫
- php連結資料庫PHP資料庫
- 資料庫測試指南資料庫
- 使用create database語句建立資料庫的詳細操作步驟Database資料庫
- Oracle資料庫中資料行遷移與行連結Oracle資料庫
- Create DatabaseDatabase
- Oracle資料庫中Create user的注意事項Oracle資料庫
- oracle xtts資料庫遷移方法測試之一OracleTTS資料庫
- oracle10g_create tablespace_測試_1Oracle
- oracle10g_create tablespace_測試_2Oracle
- PHP 單元測試與資料庫測試PHP資料庫
- 基本資料結構實現--單連結串列【含測試程式碼】資料結構
- Oracle資料庫Table,Index,Database分析統計資料方式總結及注意點(zt)Oracle資料庫IndexDatabase
- Oracle 資料庫重放(Database Replay)功能演示Oracle資料庫Database
- jmeter連結mysql資料庫JMeterMySql資料庫
- Oracle連線MongoDB資料庫OracleMongoDB資料庫
- Oracle資料庫連線方式Oracle資料庫
- Java連線oracle資料庫JavaOracle資料庫