Re: Executing Distributed Queries

From: Umachandar Jayachandran (umachandar@yahoo.com)
Date: 01/02/03


From: "Umachandar Jayachandran" <umachandar@yahoo.com>
Date: Thu, 2 Jan 2003 13:31:40 -0800


    Remote SP execution is supported only with SQL Server provider. You have
to use OPENQUERY to send the pass-through command but your SP on the remote
server should produce a result set. I have posted several examples in the
programming, odbc & server newsgroups that show how to do this with Oracle
packages & SPs. You can search for more samples in these newsgroups. I am
posting one such message here.

>>
    You have to wrap the SP call in a package that returns a table variable
as output. SO all you need is a dummy row to be returned from the package &
then you can call it using OPENQUERY using a pass-through query. I posted a
sample while back about executing DDLs in Oracle via T-SQL. Your call will
look like:

SELECT r.DummyOut
  FROM OPENQUERY( Oracle8i,
                  '{Call SomePkg.SP( {resultset dummyout, 1} )}' ) AS r
>>

>>
    You can't execute DDLs directly on remote data sources. These are not
supported by all data sources - remember that a linked server can be ADSI or
Excel.
    It is slightly tricky but you can do it. With OPENQUERY, you can execute
any pass-through statement in Oracle that returns a resultset. The key is
that the pass-through statement should return some results. This is however
difficult to accomplish in Oracle because you can't mix DDLs & statements
that return results directly in SPs (unlike in T-SQL). You can however call
a package that can return a result via table variables. So you can create a
package like below that can truncate a table:

CREATE OR REPLACE PACKAGE trunctbl
AS
 TYPE dummyout is TABLE of NUMBER(10)
 INDEX BY BINARY_INTEGER;
  PROCEDURE trunctbl( dummy OUT dummy );
END;
/
CREATE OR REPLACE PACKAGE BODY trunctbl
AS
 PROCEDURE trunctbl ( dummy OUT dummy )
 IS
 curhandle NUMBER;
 BEGIN
  curhandle := dbms_sql.open_cursor;
  dbms_sql.parse( curhandle, 'TRUNCATE TABLE owner.testtab',
dbms_sql.native );
  dbms_sql.close_cursor(curhandle);
  dummy( 1 ) := 0;
  EXCEPTION
  WHEN OTHERS THEN
      dummy( 1 ) := 1;
      dbms_sql.close_cursor(curhandle);
 END;
END trunctbl;
/

    The package above uses the "DBMS_SQL" package to execute dynamic SQL in
Oracle. The dummy table is how you return data back to OLEDB or ODBC driver.
You can process the result using the {resultset} escape syntax. So you can
now do:

select *
  from openquery( Oracle8i,
                  '{call trunctbl.trunctbl( {resultset 1, dummy} )}' )

    This will return 1 or 0.
>>

-- 
Umachandar Jayachandran
SQL Resources at http://www.umachandar.com/resources.htm
( Please reply only to newsgroup. )


Relevant Pages

  • Re: copying data oracle2sql
    ... the insert into sql server is not the problem. ... the problem is the loading part from the Oracle driver, and the overhead of the openquery syntax. ... rollback segment number XX with name YYY to small". ...
    (microsoft.public.sqlserver.datawarehouse)
  • Re: SQL 7 to Oracle Openquery
    ... it can only be processed with an Openquery, ... access what data is available in the Oracle database. ... You can join on both the data sources. ...
    (microsoft.public.sqlserver.connect)
  • Re: SQL Srvr/Oracle - help with data type conversion
    ... The table that I brought over from Oracle, as I said had numeric data types, ... but change to nvarchar in SQL Server. ... Seems that Openquery should better ...
    (microsoft.public.sqlserver.programming)
  • Re: Oracle to SQL Server Dates - Headache!
    ... > Thanks Zach, I will try the TO_DATEfunction. ... Just to be clear, the to_datefunction is an oracle function, you use ... As to using openquery, it really depends on what you're doing. ... then ALL the rows will be transfered to your sql server THEN ...
    (microsoft.public.sqlserver.programming)