Search code examples
sql-serveroracle-databaset-sqlstored-procedureslinked-server

How to capture Oracle SP INOUT parameter in SQL Server


I have Oracle linked server in my SQL Server. I created procedure which executes a stored procedure in Oracle:

CREATE PROCEDURE ModifySth (
    @var1 nvarchar(255),
    @var2 nvarchar(255)
)
AS
BEGIN
    DECLARE @var3 as NVARCHAR(255);
    EXEC('begin oracleSPname(?, ?, ? ); end;',
            @var1 output,        
            @var2,
            @var3 output,
        )
    at ORACLE
    SELECT @var1 as var1, @Vvar3 as var3;
END

When I execute ModifySth I am passing two parameters and excepting two output vars. var1 is IN OUT. How to capture var1? When I am trying to capture is, I get value which I passed to the stored procedure, not the output value.


Solution

  • Why don't you use an extra variable?

    DECLARE @var1_reply as NVARCHAR(255);
    
    EXEC('begin oracleSPname(?, ?, ?, ? ); end;',
            @var1,        
            @var1_reply output,
            @var2,
            @var3 output,
        )
    at ORACLE
    
    set @var1= @var1_reply;