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