ITPub博客

首页 > 数据库 > Oracle > oracle --- 创建DBlink

oracle --- 创建DBlink

Oracle 作者:来来来来去去去去 时间:2013-06-18 16:56:01 0 删除 编辑

当用户要跨本地数据库,访问另外一个数据库表中的数据时,本地数据库中必须创建了远程数据库的dblink,通过dblink本地数据库可以像访问本地数据库一样访问远程数据库表中的数据。

 

1 check the privilege of user

select * from user_sys_privs t

  where t.privilege like upper('%link%');

there are three kinds about it:

1) SYS CREATE DATABASE LINK NO

2) SYS DROP PUBLIC DATABASE LINK NO

3) SYS CREATE PUBLIC DATABASE LINK NO

 

2 Create the DBLINK

After you have created a database link, you can use it to refer to tables and views on the other database. In SQL statements, you can refer to a table or view on the other database by appending @dblink to the table or view name. You can query a table or view on the other database with the SELECT statement. You can also access remote tables and views using any INSERT, UPDATE, DELETE, or LOCK TABLE statement.

Defining a Public Database Link: Example The following statement defines a shared public database link named remote that refers to the database specified by the service name remote:

CREATE PUBLIC DATABASE LINK remote 
   USING 'remote'; 
shell script, e.g:
#Read the admin database name, log into catalog, create the link to admin
cat $admin_list |
while read ADMIN
do
echo "Creating database link from " $CAT " to " $ADMIN "... "
sqlplus -s $USER/$PASS@$CAT << DONE
create database link $ADMIN using '$ADMIN';
exit;
DONE
echo "Creating database link from " $ADMIN " to " $CAT "...
"
sqlplus -s $USER/$PASS@$ADMIN << DONE
create database link $CAT using '$CAT';
exit;
DONE
done
3 Use it
dsdsun02% sqlplus bsnl2010/arbor123@safx00m1
SQL*Plus: Release 10.2.0.1.0 - Production on Mon Jun 17 03:17:19 2013
Copyright (c) 1982, 2005, Oracle.  All rights reserved.

Connected to:
Oracle9i Enterprise Edition Release 9.2.0.7.0 - 64bit Production
With the Partitioning option
JServer Release 9.2.0.7.0 - Production
SQL> select max(account_no) from cmf@safx00m3
  2  ;
MAX(ACCOUNT_NO)
---------------
      598308961

参考:http://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_5005.htm

<!-- 正文结束 -->

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/23134666/viewspace-1116087/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: 没有了~
下一篇: 没有了~
请登录后发表评论 登录
全部评论

注册时间:2010-01-05