存储过程的输出参数能用表变量吗?

carven2003 2004-04-12 04:37:44
create proc test
@varTable1 table output,
@varTable2 table output
as
go

提示table附近有错误,如果不行的话。那我要在执行该存储过程后返回若干个表的内容怎么办?(用临时表?)
...全文
291 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
bpy_r 2004-06-22
  • 打赏
  • 举报
回复

sql server 现在还不支持传入表变量的参数!

的让老比尔加油啊:D

学习中
zjcxc 2004-04-12
  • 打赏
  • 举报
回复
--另一个方法是用游标变量

--存储过程救命
create proc p_test
@cu1 cursor varying output,
@cu2 cursor varying output
as
set @cu1=cursor for select top 5 name from sysobjects where xtype='U'
set @cu2=cursor for select top 5 name from sysobjects where xtype='V'
open @cu1
open @cu2
go

--调用示例
declare @cu1 cursor,@cu2 cursor,@name sysname
exec p_test @cu1=@cu1 out,@cu2=@cu2 out

print '--------游标1----------------'
fetch next from @cu1 into @name
while @@fetch_status=0
begin
print @name
fetch next from @cu1 into @name
end
close @cu1
deallocate @cu1

print '--------游标2----------------'
fetch next from @cu2 into @name
while @@fetch_status=0
begin
print @name
fetch next from @cu2 into @name
end
close @cu2
deallocate @cu2
go

--删除测试
drop proc p_test

/*--测试结果
--------游标1----------------
t
by_huikao
by_huikaobukao
B
cj_banji
--------游标2----------------
syssegments
sysconstraints

--*/
CrazyFor 2004-04-12
  • 打赏
  • 举报
回复
create proc p_test
as
select name from sysobjects
select ... from ....
select ... from ...
go
progress99 2004-04-12
  • 打赏
  • 举报
回复
函數可用表變量:

CREATE FUNCTION dbo.FunSplitStringToAraay(@vchString varchar(1000),@vchSplit varchar(10))
RETURNS @tabArray table
(
string varchar(100)
)
AS
BEGIN
...

INSERT INTO @tabArray(string)
SELECT 'abc'
...
RETURN
END
progress99 2004-04-12
  • 打赏
  • 举报
回复
如樓上所說,直接用 select * from 臨時表處理,在程式中用recordset對象提取。

如果有多個select,則在程式中用recordset對象的NextRecordset方法提取。

zjcxc 2004-04-12
  • 打赏
  • 举报
回复
--不能用表变量,可以有类似这样的方法

--示例存储过程
create proc p_test
as
select name from sysobjects
go

--调用
create table #t(name sysname)
insert #t exec p_test
select * from #t
zheninchangjiang 2004-04-12
  • 打赏
  • 举报
回复
不能用table变量,只能用游标变量

22,300

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧