15

我正在研究 sybase ASE 15。正在寻找这样的东西

Select * into #tmp exec my_stp;

my_stp 返回 10 个数据行,每行有两列。

4

4 回答 4

6

In ASE 15 I believe you can use functions, but they're not going to help with multirow datasets.

If your stored proc is returning data with a "select col1,col2 from somewhere" then there's no way of grabbing that data, it just flows back to the client.

What you can do is insert the data directly into the temp table. This can be a little tricky as if you create the temp table within the sproc it is deleted once the sproc finishes running and you don't get to see the contents. The trick for this is to create the temp table outside of the sproc, but to reference it from the sproc. The hard bit here is that every time you recreate the sproc you must create the temp table, or you'll get "table not found" errors.


    --You must use this whole script to recreate the sproc    
    create table #mine
    (col1 varchar(3),
    col2 varchar(3))
    go
    create procedure my_stp
    as
    insert into #mine values("aaa","aaa")
    insert into #mine values("bbb","bbb")
    insert into #mine values("ccc","ccc")
    insert into #mine values("ccc","ccc")
    go
    drop table #mine
    go

The to run the code:


create table #mine
(col1 varchar(3),
col2 varchar(3))
go

exec my_stp
go

select * from #mine
drop table #mine
go
于 2008-10-06T19:34:31.217 回答
5

我刚遇到这个问题,迟到总比没有好...

这是可行的,但在对接中是一个巨大的痛苦,涉及一个 Sybase“代理表”,它是另一个本地或远程对象(表、过程、视图)的代表。以下适用于 12.5,较新的版本希望有更好的方法。

假设您有一个存储过程定义为:

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

首先切换到 tempdb:

use tempdb

然后创建一个代理表,其中列与结果集匹配:

create existing table myproxy_extractSomething (
column_a int not null, -- make sure that the types match up exactly!
column_b varchar(20) not null,
_timestamp datetime null,
primary key (column_a)) external procedure at "loopback.mydb.mylogin.sp_extractSomething"

注意事项:

  • “loopback”是 localhost 的 Sybase 等价物,但您可以将其替换为在服务器的 sysservers 表中注册的任何服务器。
  • 当 Sybase 执行存储过程时,_timestamp 参数被转换为 @timestamp,并且所有像这样声明的参数列都必须定义为 null。

然后,您可以从您自己的数据库中像这样从表中选择:

declare @myTimestamp datetime
set @myTimestamp = getdate()

select * 
from tempdb..myproxy_extractSomething
where _timestamp = @myTimestamp

这很简单。然后插入临时表,首先创建它:

create table #myTempExtract (
    column_a int not null, -- again, make sure that the types match up exactly
    column_b varchar(20) not null,
    primary key (column_a)
)

并结合:

insert into #myTempExtract (column_a, column_b)
select column_a, column_b
    from tempdb..myproxy_extractSomething
    where _timestamp = @myTimestamp
于 2011-04-06T16:50:32.770 回答
-1

如果 my_stp 通过计算来自不同表的值来填充数据,您可以创建一个与 my_stp 完全相同的等效视图。

CREATE VIEW My_view
 AS
/*
  My_stp body
*/


Then select data from view 
SELECT *  INTO #x FROM my_view
于 2014-08-30T07:14:16.233 回答
-1

不确定 Sybase,但在 SQL Server 中应该可以:

插入 #tmp (col1,col2,col3...) exec my_stp

于 2008-10-03T10:03:39.227 回答