SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


linked server return from Oracle into table variable


linked server return from Oracle into table variable

Author
Message
sqlgirlatty
sqlgirlatty
Valued Member
Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)

Group: General Forum Members
Points: 66 Visits: 230
<<previously posted to wrong forum>
I'm trying to return the contents of a select statement on Oracle into a table variable in SQL Server stored procedure. I can get the query to return a single value into multiple variables, but getting a result set to return to a table variable has been tricky.

DECLARE @vlparent varchar(10)
,@sqlstring nvarchar(4000);

DECLARE @rset TABLE
(ln varchar(64)
,fn varchar(64)
,bd varchar(10)
,vlname varchar(10)
);

SET @sqlstring = N' DECLARE CURSOR mb IS SELECT CUST_LASTNAME, CUST_FIRSTNAME,CUST_DOB,VOL_NAME
FROM ORASCHEMA.TABNAME WHERE VOL_PARENT = ?;
TYPE mb_array IS TABLE OF mb%ROWTYPE;
cur_array mb_array;
BEGIN OPEN mb;
LOOP
FETCH mb BULK COLLECT INTO cur_array LIMIT 1000;
EXIT WHEN mb%NOTFOUND;
END LOOP;
CLOSE mb;
END;'
EXEC(@sqlstring,@vlparent,@rset OUTPUT)AT ORA_LINKSERVER

With this method I receive an error about undefined scalar value. With a INSERT INTO ..EXEC receive an error about MSDTC not recognizing my server. Any ideas?
sqlgirlatty
sqlgirlatty
Valued Member
Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)

Group: General Forum Members
Points: 66 Visits: 230
Went about it in a completely different fashion and solved it.
Note, EXEC <stmt> AT far_server didn't yield what was needed. Had to make dynamic sql with OPENQUERY.
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