【发布时间】:2016-05-13 03:46:06
【问题描述】:
我目前正在使用 Sybase ASE 15.7 并编写一个使用另一个 SP 的结果的存储过程。我想调用它并将结果插入到临时表中,因此不需要对原始 SP 进行修改。
参考此帖: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始终为null。如何在代理表中定义输出参数?
【问题讨论】:
标签: sql stored-procedures sybase