Solved

Return recordset from Oracle via Linked Server and OPENQUERY

Posted on 2008-06-09
5
3,680 Views
Last Modified: 2010-05-18
I have verified that I am able to use OPENQUERY to query tables in the linked server, even the table being queried from within the oracle stored procedure.  I have already executed the oracle stored procedure from the oracle command line utility and it works properly.

I have tried so many variations of the openquery and changes to the oracle procedure that i'm out of options.  Here is the error message i receive when running the openquery (see code snippet's).

(note: i have tried it using the MS Oledb Driver for Oracle and the Oracle provided drivers, same result, though a slightly different message - both still indicate the "no columns" issue)

OLE DB error trace [Non-interface error:  OLE DB provider unable to process object, since the object has no columnsProviderName='OraOLEDB.Oracle', Query=GET_AGE_OF_FIRST_OFFENSE'].
Msg 7357, Level 16, State 2, Line 1
Could not process object 'GET_AGE_OF_FIRST_OFFENSE'. The OLE DB provider 'OraOLEDB.Oracle' indicates that the object has no columns.

To give the bigger picture, a third party vendor (with an oracle database) has some data for our application to consume. Our application is limited to only using OPENQUERY to get that data and insert it into our database for later processing.  For 99% of the data the vendor has provided views that we can query without any issues using OPENQUERY - however, they have one stored procedure that returns a ref cursor and we need to receive it via OPENQUERY and subsequently insert it into one of our local tables (its more complicated than that, but suffice to say, we are stuck with openquery and stuck with the remote data coming from a stored procedure).

If all were working well we would do something like this

INSERT INTO OUR_LOCAL_TABLE
EXEC(@SQL)

where @SQL contains the openquery dynamic SQL - again, this works wonderfully when the remote data is in a view, but we get the above error when the remote data is in a stored procedure.

thank you


Oracle code example:
create or replace PROCEDURE GET_AGE_OF_FIRST_OFFENSE  
( t_cursor OUT SYS_REFCURSOR ) 
AS
BEGIN
    OPEN t_cursor FOR 
        select * from age_of_first_offense;
END GET_AGE_OF_FIRST_OFFENSE;
 
Openquery example(s):
select * from openquery(ORACLE_TEST,'GET_AGE_OF_FIRST_OFFENSE')

Open in new window

0
Comment
Question by:bryanparke
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
LVL 1

Expert Comment

by:dotnetpro
ID: 21748210
How about if you did like this in the last line of your code snippet ?
select * from openquery(ORACLE_TEST,'Execute GET_AGE_OF_FIRST_OFFENSE'). I think with in the single quotes it should be a proper Oracle syntax for executing a sproc.

0
 

Author Comment

by:bryanparke
ID: 21799358
For some reason it (Oracle) still doesn't accept this, same exact error.  I'm at a loss. Thanks for the suggestion.
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 21826548
I had the same problem, and the only way to get anything working was to use a FUNCTION with the PIPELINED method, here some sample code:
http://www.oracle-base.com/articles/9i/PipelinedTableFunctions9i.php

in your linked query:

select * from openquery(ORACLE_TEST,' SELECT * FROM TABLE(GET_AGE_OF_FIRST_OFFENSE_FUNCTION) ' )
0
 

Author Comment

by:bryanparke
ID: 21832900
thank you angellll - i will give this a try.  because we didn't find a way to make a stored procedure to work, the external vender re-wrote the procedure into a view (must be a nasty looking view in order to do what we needed, but they made it happen) - so for now the problem is averted, but i'm sure we will run into this again.  I'm going to give you the points because i'm sure it will work.  thanks again.
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
get count of orders by customer Sql Server table. 3 48
SQL Server replace between tags 6 30
SQL query 45 41
first parameter x of the decimal (x, y) 1 29
Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question