如何将存储过程的结果集插入临时 table 并在 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 结果的存储过程。我想调用它并将结果插入临时文件 table 因此原始 SP 不需要修改。
参考这个post:How can I get data from a stored procedure into a temp table?
Jakub 使用代理 tables 的回答与示例 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
我定义和使用代理 tables 如下:
--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。如何在代理中定义输出参数 table?
原来在存储过程中连创建代理表都不行。将弹出以下错误:
Statement with location clause must be the only statement in a query batch
所以我猜想在Sybase sp中没有办法在不修改原始数据集的情况下使用另一个sp的结果数据集。不幸的是,似乎剩下的唯一方法就是复制原始 sp(有 1.4k 行)。
我目前正在使用 Sybase ASE 15.7 并编写一个使用另一个 SP 结果的存储过程。我想调用它并将结果插入临时文件 table 因此原始 SP 不需要修改。
参考这个post:How can I get data from a stored procedure into a temp table?
Jakub 使用代理 tables 的回答与示例 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
我定义和使用代理 tables 如下:
--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。如何在代理中定义输出参数 table?
原来在存储过程中连创建代理表都不行。将弹出以下错误:
Statement with location clause must be the only statement in a query batch
所以我猜想在Sybase sp中没有办法在不修改原始数据集的情况下使用另一个sp的结果数据集。不幸的是,似乎剩下的唯一方法就是复制原始 sp(有 1.4k 行)。