簡體   English   中英

如何將存儲過程的結果集插入到臨時表中並獲取Sybase中的輸出參數?

[英]How do I insert the result set of a stored procedure into a temp table AND get the output parameters in Sybase?

我目前在Sybase ASE 15.7上,正在編寫使用另一個SP的結果的存儲過程。 我想調用它並將結果插入到臨時表中,因此不需要對原始SP進行修改。

參考此文章: 如何將數據從存儲過程獲取到臨時表中?

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始終為null。 如何在代理表中定義輸出參數?

即使存儲過程中不允許創建代理表,它也會被淘汰。 將彈出以下錯誤:

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

因此,我猜想在Sybase sp中,如果不修改原始sp的結果數據集就無法使用它。 不幸的是,似乎剩下的唯一方法就是復制原始sp(具有1.4k行)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM