0% found this document useful (0 votes)
100 views

O11g Dblink Setting

The document demonstrates how to create and use database links in Oracle Database 11g to access and manipulate data across databases on remote hosts. It provides steps to create a database link using a tnsnames.ora file entry as well as using an easy connect string without modifying tnsnames.ora. Examples are given to select, insert, delete, update data on the remote database and commit transactions using the database links.

Uploaded by

Pokemon8
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
100 views

O11g Dblink Setting

The document demonstrates how to create and use database links in Oracle Database 11g to access and manipulate data across databases on remote hosts. It provides steps to create a database link using a tnsnames.ora file entry as well as using an easy connect string without modifying tnsnames.ora. Examples are given to select, insert, delete, update data on the remote database and commit transactions using the database links.

Uploaded by

Pokemon8
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

============================================================= Subject: Database Links for Oracle Database 11g Purpose: To demonstrate Oracle Database Links ============================================================= Example

------The user SCOTT wants to manipulate data of the database "orcl" on a remote host "DBHOST" through the port 1521 with the default listener on the remote host. Steps: Create a database link using the service name "host2_db2" in the file tnsnames.o ra. Part of the file tnsnames.ora on the local host: host2_db2 = (DESCRIPTION = (ADDRESS = (DBHOSTTOCOL = TCP)(HOST = DBHOST)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = orcl) ) ) Grant some privileges to user who will create database links. The local user must have the privileges "CREATE DATABASE LINK, CREATE PUBLIC DATABASE LINK". The remote user must have the privilege "CREATE SESSION". On the remote host: SQL> connect system/<pass_word> SQL> GRANT CREATE SESSION TO scott; SQL> ALTER USER scott ACCOUNT UNLOCK; On the local host: SQL> connect system/<pass_word> SQL> GRANT CREATE DATABASE LINK, CREATE PUBLIC DATABASE LINK, CREATE SESSION TO scott; SQL> ALTER USER scott ACCOUNT UNLOCK; SQL> connect scott/tiger SQL> CREATE DATABASE LINK dblink2 CONNECT TO scott IDENTIFIED BY tiger USING 'host2_db2'; SQL> SELECT * FROM dept@dblink2; SQL> INSERT INTO dept@dblink2 VALUES(...); SQL> DELETE FROM dept@dblink2 WHERE deptno = ...; SQL> UPDATE dept@dblink2 SET dname = '...' WHERE deptno = ...;

SQL> COMMIT; SQL> SELECT emp.ename, emp.deptno, dept.dname FROM emp, dept@dblink2 WHERE emp.deptno = dept.deptno; END OF BASIC DATABASE LINK ------------------------------------------------Advanced database link. The following statement works on Oracle 10.2 onwards. Create a database link using Easy Connect method without modifying tnsnames.ora. SQL> CREATE DATABASE LINK dblink3 CONNECT TO peter IDENTIFIED BY password USING 'DBHOST:1521/OLTP'; SQL> SELECT * FROM dept@dblink3; ------------------------------------------------Connect to a remote database using Easy Connect without any database link: $ sqlplus scott/tiger@DBHOST:1521/OLTP or $ sqlplus scott/tiger@DBHOST/OLTP -- The default port is 1521 or $ sqlplus scott/tigerd@DBHOST -- The default service name is the valud of -- DEFAULT_SERVICE_listener_name in listener.ora

You might also like