Sunteți pe pagina 1din 4

Create a DBLink

The Oracle docs note the syntax for creating an Oracle dblink as follows:

CREATE [ SHARED ] [ PUBLIC ] DATABASE LINK dblink


[ CONNECT TO
{ CURRENT_USER
| user IDENTIFIED BY password
[ dblink_authentication ]
}
| dblink_authentication
]
[ USING 'connect_string' ] ;

 Oracle has invested heavily in distributed database technology and the creation of a
database link is very straightforward.  You specify the dblink name, the remote user to
connect to, the password for the remote user and the TNS service name for the database
link connection:

create public database link


  mylink
connect to
  remote_username
identified by
  mypassword
using 'tns_service_name';

create database link DBLink_LMCWIP01 connect to LMCWIP01 identified by


welcome_wip using ‘

CREATE DATABASE LINK "RIJMASTER.WORLD" CONNECT TO "CBDSIEPMAN" IDENTIFIED by


"******" USING '(DESCRIPTION=(ADDRESS=(COMMUNITY=TCP.world)(PROTOCOL=TCP)
(Host=EAGLE.SIEP.SHELL.COM)(Port=1521))(CONNECT_DATA=(SID=EDW817P)
(SERVER=DEDICATED)))'

or CREATE DATABASE LINK "RIJMASTER.WORLD" CONNECT TO "CBDSIEPMAN" IDENTIFIED by


"******" USING 'tnsnames';

desc LMCWIP01.activity@DBLink_LMCWIP01

create database link FXPGSM2P connect to rptmig identified by rptmig


using 'FXPGSM2P.WORLD';
SELECT
DBMS_METADATA.GET_DDL('DB_LINK','ACSP_FXGSM1U2.WORLD','PUBLIC') from
dual;

SQL> select * from dba_db_links;

no rows selected

SQL> create database link DBLink_LMCWIP01 connect to LMCWIP01 identified by welcome_wip


using 'WIPPNGP';

Database link created.

SQL>

SQL> desc LMCWIP01.Z_REPORTING_DATES@DBLINK_LMCWIP01

Name Null? Type

----------------------------------------- -------- ----------------------------

LAST_YIELD_UPDATE_DATE DATE

DBLink problem :

Connected to WIPPNGP1 and checked if the object exist under LMCWIP01 :

SQL>select object_name from dba_objects where owner = ‘LMCWIP01’;

OBJECT_NAME
--------------------------------------------------------------------------------
Z_REPORTING_DATES
Z_STORED_PROC_ERRORS
Z_LOT_YIELDS
Z_LOT_YIELDS_PK
Z_LOT_YIELDS_WF_STEP
Z_LOT_YIELDS_WF_STEP_PK

3680 rows selected.


Connected to WIPSGPP1 and test run the command below :

SQL> desc LMCWIP01.Z_REPORTING_DATES@DBLINK_LMCWIP01

Name Null? Type

----------------------------------------- -------- ----------------------------

LAST_YIELD_UPDATE_DATE DATE
You can also create a dblink to non-Oracle databases,  Francisco Riccio describes the
steps for a database link to MySQL:

Step 1:  Your first step is having installed the TRANSPARENT GATEWAY (it comes in
as of the options when you install Oracle).

Step 2: You must have a user in the SQL Server.

Step 3: In the directory <ORACLE_HOME>\tg4msql\admin look for the file


inittg4msql.ora and have the following options:
HS_FDS_CONNECT_INFO="SERVER=name_server;DATABASE=name_db"
HS_FDS_TRACE_LEVEL=OFF
HS_FDS_RECOVERY_ACCOUNT=user_sqlserver
HS_FDS_RECOVERY_PWD=pass_user_sqlserver

Step 4: Configure the listener and add the following


(SID_DESC =
(PROGRAM = tg4msql)
(SID_NAME = MSQL)
(ORACLE_HOME = C:\oracle1)
)
)

and in our tnsnames.ora add


MSQL=
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = servidor)(PORT = 1521))
)
(CONNECT_DATA =
(SID = MSQL)
)
(HS=OK)
)

where HS set up as a heterogonous service

Step 5: create a link to sql server.


create database link msql connect to user_sqlserver identified by password using 'MSQL';

Step 6: You can now use the database link to a foreign database:
select * from table@msql

S-ar putea să vă placă și