How to Select Table SQL To Oracle - sql

I want to select data from SQL Server to Oracle (Toad Apps).
If from Oracle to SQL Server its done like this
Insert Into M_CLASSIFICATION_ORACLE
SELECT * From OPENQUERY ([B1APPS], 'select * from V_Classification_Asset' ) AS derivedtbl_1
How about in Oracle (Toad apps)?

You can able to do it by using CREATE DATABASE LINK:
Create a Database Link to connect to SQL Server:
CREATE DATABASE LINK link-name ...
Query SQL Server using the Database Link:
SELECT * FROM sqlserver-table-name#link-name;
Documentation:
https://www.oracletutorial.com/oracle-administration/oracle-create-database-link/
Calling Stored Procedure using Database Link:
https://dba.stackexchange.com/questions/1856/running-a-stored-procedure-across-db-link

Related

Oracle equivalent of suser_name() used in SQL Server

What is the Oracle equivalent of suser_name() used in SQL Server
Mostly they use SYS_CONTEXT for tracking and auditing purposes like the one below :
SELECT SYS_CONTEXT ('USERENV', 'SESSION_USER')
FROM DUAL;
we can get the login identification name of the user by using SUSER_NAME ( [ server_user_id ] ) on SQL Server
try Use the FND_USER table on oracle .
use sif you have the Server_user_id

Linked Server: MO_GLOBAL.SET_POLICY_CONTEXT('S', 83);

I have a linked server (SQL Server 2008 to Oracle) and would like to know how to execute this statement before I query the data:
MO_GLOBAL.SET_POLICY_CONTEXT('S', 83);
I can query the data using this:
Select * from OPENQUERY (linkedservername, 'Select * from tablename')
But I'm not sure how to incorporate the set_policy_context statement. Appreciate any feedback.
Here's the correct statement:
EXECUTE('BEGIN apps.MO_GLOBAL.SET_POLICY_CONTEXT(''S'', 83); END;') at tablename;

How to find linked_server name in sql server management studio?

I am trying to query the following in sql server management studio:
select colname from openquery (linked_server, 'exec XX.YY.PrcName #Parameter')
When i try to give XX as linked server name i am getting an error.
Is that right or how do i find the linked_server name ?
To check linked server name :
select * from sys.sysservers
you can easily run any procedure in another server through linked server as:
exec <procedure name><parameneters> at <linked server name>
To get a list of linked servers use:
EXEC SP_LINKEDSERVERS
If you want to SELECT something from Linked server:
SELECT *
FROM [SOMESERVER\SOMEINSTANCE].somedatabase.dbo.sometable;
To EXECUTE something on linked server:
EXEC [SOMESERVER\SOMEINSTANCE].somedatabase.dbo.somestoredprocedure
SELECT *
FROM OPENQUERY([SOMESERVER\SOMEINSTANCE].somedatabase.dbo.somestoredprocedure)
More info:
sqlauthority
MSDN
You also can use sys.servers
Select * From SYS.SERVERS
When server_id = 0, this is the server name.
When server_id >0 , this is the local name of linked server.

How to INSERT INTO SQLite with SELECT FROM SQL Server

I want to SELECT a table in a SQL Server database and then INSERT it into a local SQLite database.
IS it possible to do this entirely with a query in the vein of:
INSERT INTO table1 ( column1 )
SELECT col1
FROM table2
but passing connection information?
Setup a local odbc data source, DSN, for SQLite file. Call it SQLite_DataSource
Then setup a linked server in SSMS:
USE [master]
GO
EXEC sp_addlinkedserver
#server = 'SQLite', -- the name you give the server in SSMS
#srvproduct = '', -- Can be blank but not NULL
#provider = 'MSDASQL',
#datasrc = 'SQLite_DataSource'
GO
Then you can use it like any other db:
INSERT into SQLite_DataSource (column1)
SELECT col1
FROM table2
Lookup SQL Server's documentation for sp_addlinkedserver for more details.
You need to create a SQL Server Linked Server to SQLite, take a look at this post for more information .

How do I execute a stored procedure on linked Firebird server in SQL Server 2008

I have a linked Firebird database on my SQL Server 2008 via ODBC.
I can execute a query like this and I get the wanted results:
SELECT * FROM OPENQUERY(LINKED_SERVER_NAME, 'SELECT * FROM TABLE_NAME')
Now i wonder how can I execute stored procedure with one parameter input.
I have tried:
SELECT * FROM OPENQUERY(LINKED_SERVER_NAME, 'STORED_PROCEDURE_NAME 00001')
and
EXEC LINKED_SERVER_NAME.STORED_PROCEDURE_NAME '00001'
with no success...
Any tip would be appreciated !
I dont know in MSSQL but you can try
SELECT * FROM OPENQUERY(LINKED_SERVER_NAME, 'SELECT * FROM STORED_PROCEDURE_NAME(00001)')