Linked ServerSetup with Oracle in SQL Server:
oracle or other database products using T-SQL via SQL server database Engine
then you need to configure Linked Server.
server with oracle.
where you want to configure linked server.
Client Installation Directory]\product\11.2.0\]dbhome_1\NETWORK\ADMIN
configuration file for oracle)
Example here
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS =
(PROTOCOL = TCP)
(HOST = 192.168.10.10)
(PORT = 1521)
)
)
(CONNECT_DATA =
(SERVICE_NAME = PROD)
)
)
connection.
Object tree Node and see linked server
select New Linked Server and Enter
required information
credentials
configured now.
a.*
OPENQUERY(linkedservername,'SELECT *from oracledatabasename.table_or_view') a;
Syntax of OPENQUERY
OpenQuery you can INSERT,DELETE , UPDATE,DELETE.
Select Query:
a.*
OPENQUERY(PRODNEW,'SELECT *from Apps.customer_details') a;
OPENQUERY (PRODNEW, ‘SELECT ID,name FROM Apps.customer_details’)
OPENQUERY (PRODNEW, 'SELECT name FROM Apps.customer_details
WHERE id = ''C121'''
)name = 'Uma Shankar
Patel'
;OPENQUERY (PRODNEW, 'SELECT ID FROM Apps.customer_details
WHERE ID = ''C121'''
);fetch data from oracle via SQL server database engine.
little about linked server.I have learned this when my client require to
develop a web site that fetch data from sql server but customer data of client
comes from oracle.
- Insert data from Oracle to SQL Server over linked server
(col1,col2,col3)SELECT a.* FROM OPENQUERY(likedservaername,'SELECT col1,col2,col3from oracletablename') a;
- Insert data from SQL server to Oracle over linked server
INSERT INTO OPENQUERY(linkedservername,'select col1,col2,col3 fromoracletablename'
)
SELECT col1, col2, col3 FROM sqldatabase.dbo.tablename;
- Delete data from Oracle over linked server
DELETE OPENQUERY (linkedserver, 'Select *from oracetablename');
In the same way you can create linked server with oracle,mysql and other rdbms and can use above sample query as required. Update oracle table from SQL Server
UPDATE u SET u.oraclefieldname = ‘value’fromopenquery(likedservername,'select *from oracletable') as uwhere u.hdr_id = @rid
oracletablename'
)- Delete data from Oracle over linked server
Update oracle table from SQL Server
UPDATE uSET u.oraclefieldname = ‘value’fromopenquery(likedservername,'select *from oracletable') as uwhere u.hdr_id = @rid