程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> Oracle數據庫 >> Oracle數據庫基礎 >> Oracle DBLink簡單運用

Oracle DBLink簡單運用

編輯:Oracle數據庫基礎

我簡單做了一個例子,實現以上要求.
首先進行適當授權:

[oracle@jumper Oracle]$ sqlplus "/ as sysdba"

SQL*Plus: Release 9.2.0.4.0 - Production on Tue Nov 7 21:07:56 2006

Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.


Connected to:
Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
With the Partitioning option
JServer Release 9.2.0.4.0 - Production

SQL> grant create public database link to eygle;

Grant succeeded.
SQL> grant all on dbms_Flashback to eygle;

Grant succeeded.

建立DB Link:

SQL> connect eygle/eygle
Connected.
SQL> create public database link hsbill using ''hsbill'';

Database link created.

SQL> select db_link from dba_db_links;

DB_LINK
---------------------------------------------------
HSBILL

SQL> select * from dual@hsbill;

D
-
X

此後可以嘗試使用DB Link進行遠程和本地執行:

SQL> set serveroutput on
SQL> set feedback off
SQL> declare
2 r_gname varchar2(40);
3 l_gname varchar2(40);
4 begin
5 execute immediate
6 ''select GLOBAL_NAME from global_name@hsbill'' into r_gname;
7 dbms_output.put_line(''gname of remote:''||r_gname);
8 select GLOBAL_NAME into l_gname from global_name;
9 dbms_output.put_line(''gname of locald:''||l_gname);
10 end;
11 /
gname of remote:HSBILL.HURRAY.COM.CN
gname of locald:EYGLE

遠程Package或Function調用也可以隨之實現:

SQL> declare
2 r_scn number;
3 l_scn number;
4 begin
5 execute immediate
6 ''select dbms_Flashback.GET_SYSTEM_CHANGE_NUMBER@hsbill from dual'' into r_scn;
7 dbms_output.put_line(''scn of remote:''||r_scn);
8 end;
9 /
scn of remote:18992092687

SQL>

-The End-

 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved