Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Oracle and SQL Server Data Interoperability Issues - Part 1


Oracle and SQL Server Data Interoperability Issues - Part 1

Author
Message
gdavidson-740471
gdavidson-740471
Forum Newbie
Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)

Group: General Forum Members
Points: 8 Visits: 23
I'm running into the same problems with OPENQUERY. Not being able to provide it with a string argument containing a dynamically created query is just brain-dead as far as I can see. I, too would like to see the rationale for this.

Building up the entire SQL server SQL statement is fine if you simply want to display the output of a query but I need to be able to set variables in a stored procedure or trigger with values abstracted from an Oracle database for further use, but variables set inside an sp_executesql call are localised. Thus

ALTER PROCEDURE SR_numinput
@SR_num VARCHAR(20),
@cust Varchar(50) OUTPUT,
@proj varchar(20) OUTPUT
AS
BEGIN
declare @query NVARCHAR(500);
set @query =
'select @cust = NAME, @proj = PROJ_NUM FROM
openquery(AtlasTest,
''Select P.NAME,P.PROJ_NUM from SXXX.S_SRV_REQ S, SXXX.S_PROJ P
where p.row_id=s.proj_id and s.sr_num='''''+@SR_Num + ''''' '')';
--select @query;
execute sp_executesql @query;
select @cust as oCustomer, @proj as oProject;
END

puts out a msg states that @cust must be declared when the statement is executed, and @cust declared in the procedure itself does not get set.


Any workarounds gratefully received - Thanks
Giles
gdavidson-740471
gdavidson-740471
Forum Newbie
Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)

Group: General Forum Members
Points: 8 Visits: 23
Got it - using some of the hints earlier in the thread:

ALTER PROCEDURE SR_numinput
@SR_number VARCHAR(20),
@customer VARCHAR(50) OUTPUT,
@project VARCHAR(20) OUTPUT
AS
BEGIN
declare @query NVARCHAR(500);
declare @parm NVARCHAR(500);
set @parm = N'@cust VARCHAR(50) OUTPUT,
@proj VARCHAR(50) OUTPUT';

set @query =
'select @cust = NAME, @proj = PROJ_NUM FROM
openquery(AtlasTest,
''Select P.NAME,P.PROJ_NUM from SXXX.S_SRV_REQ S, SXXX.S_PROJ P
where p.row_id=s.proj_id and s.sr_num='''''+@SR_Number + ''''' '')';
select @query;
execute sp_executesql @query,
@parm,
@Cust = @customer OUTPUT,
@Proj = @project OUTPUT;
select @customer as oCustomer, @project as oProject;
END


Build up the select string with the input values included.
Then use sp_executesql with defining the OUTPUT variables required, and map them to the procedure/trigger variables in the call.

Kind of ugly, but there it is.
pearsonrken
pearsonrken
Forum Newbie
Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)

Group: General Forum Members
Points: 3 Visits: 8
Did you ever resolve this issue?

Ken Pearson
gdavidson-740471
gdavidson-740471
Forum Newbie
Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)

Group: General Forum Members
Points: 8 Visits: 23
My second post showed how I got around the problem - it offends my aesthetic sensibilities but that's TSQL for you.
arpit.decompiler
arpit.decompiler
Forum Newbie
Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)

Group: General Forum Members
Points: 2 Visits: 13
You proposed a work-around for using select openquery but not when using insert openquery. I'd appreciate if you could suggest a work around when inserting into a timestamp column from SQL server using Oracle Linked Server. Here is my syntax:

insert OPENQUERY(OracleLinkedServer, 'SELECT [Other Columns], TimeStampColumn FROM OracleSchema.OracleTable')
select @data, CONVERT(datetime2(7),'2007-05-02T19:58:47.1234567')

TimeStampColumn in Oracle has a datatype of TIMESTAMP(6). I tried all the following to insert timestamps in Oracle but I get the same error in all cases:

Error:
OLE DB provider "MSDAORA" for linked server "" returned
message "Oracle error occurred, but error message could not be retrieved
from Oracle.".
OLE DB provider "MSDAORA" for linked server "" returned
message "Data type is not supported.".
Msg 7321, Level 16, State 2, Line 5
An error occurred while preparing the query "" for execution against OLE DB provider "MSDAORA" for linked server "".
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search