2016-05-13 39 views
0

我目前在Sybase ASE 15.7上編寫使用另一個SP結果的存儲過程。我想調用它並將結果插入臨時表中,因此不需要對原始SP進行任何修改。如何將存儲過程的結果集插入臨時表中並在Sybase中獲取輸出參數?

指的這個帖子:How can I get data from a stored procedure into a temp table?

的Jakub的答案使用代理表與樣品SP定義完美的作品:

create procedure mydb.mylogin.sp_extractSomething (
@timestamp datetime) as 
select column_a, column_b 
    from sometable 
    where timestamp = @timestamp 

但是還有最後一件遺失!你如何獲得輸出參數和結果集?在我的情況下,SP的定義如下所示:

create procedure mydb.mylogin.sp_extractSomething 
(
    @timestamp datetime, 
    @errcode char(10) output 
) as 
    select @errcode='NOERR' 
    select column_a, column_b 
     from sometable 
     where timestamp = @timestamp  
    if (@@rowcount = 0) 
    begin 
     select @errcode = 'ERR001' 
    end 

我定義和使用的代理表如下:

--create proxy table 
create existing table myproxy_extractSomething (
column_a int not null, 
column_b varchar(20) not null, 
_timestamp datetime null, 
_errcode char(10) null) external procedure at "loopback.mydb.mylogin.sp_extractSomething" 

--calling sp 
declare @errcode Char 
declare @myTimestamp datetime 
set @myTimestamp = getdate() 

select * 
from myproxy_extractSomething 
where _timestamp = @myTimestamp 
and _errcode = @errcode 
select @errcode 

雖然結果集可以成功返回,@errcode/_errcode是始終爲空。如何在代理表中定義輸出參數?

回答

0

即使創建代理表,它也不會在存儲過程中實現。以下錯誤會彈出:

Statement with location clause must be the only statement in a query batch 

所以我想在Sybase SP沒有辦法用結果數據集另一個SP的不修改原來的。不幸的是,似乎剩下的唯一辦法就是複製orignal sp(它有1.4k行)。

相關問題