March 17, 2006 at 9:04 am
Hi, I'd like to know if it's possible to get the equivalent of and output parameter back from an SQL stored procedure which uses OPENQUERY to insert a record to an Oracle linked server.
e.g.
INSERT OPENQUERY (ORACLE,
'SELECT
ColumnID,
Value RECORDCD,
FROM Table WHERE 1=2')
VALUES (1, @Value);
ColumnID is the identity and I'd like to get this value back from the insert if possible (it appears I need to set it to 1 in the insert statement to allow this to work, but it does insert with a new value ok!).
I'm not sure if this is possible though - can anyone help?
Thanks
March 20, 2006 at 8:00 am
This was removed by the editor as SPAM
May 22, 2018 at 7:51 pm
any update on the topic? I am facing the same issue.
Thank you
May 22, 2018 at 9:30 pm
dotnet85 - Tuesday, May 22, 2018 7:51 PMany update on the topic? I am facing the same issue.
Thank you
I don't know what ORACLE uses as a "last row marker inserted" but it's not likely that OPENQUERY can provide such a return.
--Jeff Moden
Change is inevitable... Change for the better is not.
May 23, 2018 at 2:54 pm
Jeff Moden - Tuesday, May 22, 2018 9:30 PMdotnet85 - Tuesday, May 22, 2018 7:51 PMany update on the topic? I am facing the same issue.
Thank youI don't know what ORACLE uses as a "last row marker inserted" but it's not likely that OPENQUERY can provide such a return.
Besides the fact that the insert happened on the remote server, so the local server's @@identity would not be getting updated as a result.
----------------------------------------------------------------------------------
Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?
May 24, 2018 at 12:09 am
Thank you for your both replies and clarifications.
But why SQL Server looks like parsing the query provided inside OPENQUERY, though the statement is meant to be executed on the remote server (i.e., Oracle)?
I have tried different ways, but still getting errors. Here they are:
using Sequence CURRVAL
DECLARE @SOMEID BIGINT;DECLARE @QUERY NVARCHAR(MAX) = N'INSERT OPENQUERY(ORACLE_SERVER2, ''SELECT CODE, DESCS, CREATED_BY FROM STORAGE_TYPE'')VALUES(''1234'', ''1234DESC'', ''TESTTEST''); SELECT STORAGE_TYPE_SEQ.CURRVAL INTO @SOMEID FROM DUAL;';EXEC SP_EXECUTESQL @QUERY, N'@SOMEID BIGINT', @SOMEID OUTPUT;SELECT @SOMEID;
Msg 102, Level 15, State 1, Line 90 Incorrect syntax near '@SOMEID'.
(1 row(s) affected)
using RETURNING
statement
DECLARE @SOMEID BIGINT;DECLARE @QUERY NVARCHAR(MAX) = N'INSERT OPENQUERY(ORACLE_SERVER2, ''SELECT CODE, DESCS, CREATED_BY FROM STORAGE_TYPE'')VALUES(''1234'', ''1234DESC'', ''TESTTEST'') RETURNING ID INTO @SOMEID';EXEC SP_EXECUTESQL @QUERY, N'@SOMEID BIGINT', @SOMEID OUTPUT;SELECT @SOMEID;
Msg 102, Level 15, State 1, Line 90 Incorrect syntax near 'RETURNING'.
(1 row(s) affected)
Thank you
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply