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