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

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;

Related

How to Select Table SQL To Oracle

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

How to insert value into DB2 from SQL Server using openquery which are not already inserted?

Is there any option to use not exists in openquery from SQL Server and prevent insert of values which already exist in DB2, from table.
I want to insert data from a table located in SQL Server into a table located in an IBM DB2 server, but I want to check if the value already exists or not.
This works for me actually,
if not exists (select * from openquery(puskarkc, 'select * from puskarlib.castatus'))
begin
insert openquery (puskarkc, 'select * from puskarlib.castatus')
select * from castatus
end

How to extract part of SQL query from a table

Is it possible to to extract SQL queries that are saved in a table?
For example
select * from saved_queries
name | statement
queryname | 'select * from mytable where myfield = 'somevalue'
I would like to be able to do something like
select * from ( extractsomehow( 'select Statement from saved_queries where name = 'queryname') ).
Unfortunately I cannot use Java so I am restricted to SQL and XML there.
I am using Oracle 11g
If you can write a stored procedure, you could use execute immediate, something like this:
select statement into v_statement from saved_queries where ... ;
execute immediate v_statement;
Before you use dynamic SQL, think carefully about whether or not you actually need it.

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)')

SQL Query: How to query a function/procedure body-script

is there any Query syntax (predefined )in SQL Server can show a function/procedure body-script?
sth like:
Select * from ShowScript('MyFunctionOrProcedureName')
I think you want
exec sp_helptext 'MyFunctionOrProcedureName'