create table #tmp (id
int)
declare @x
int set @x=1 while @x<=10
begin insert into #tmp
values(@x)
set @x=@x+1
end declare tmpCursor
CURSOR for select *
from #tmp
open tmpCursor
declare @id
int fetch next from tmpCursor
into @id while @@FETCH_STATUS =0
begin print @id
fetch next from tmpCursor
into @id
end
create
procedure
findName
--创建一个名为findName的存储过程
AS
declare
@result
VARCHAR
(30)
--用来处理结果的变量
begin
--声明一个游标
Declare
curStudentFee
Cursor
for
SELECT
NAME
FROM
SYSOBJECTS
WHERE
XTYPE=
'P'
;
---查询语句(查询所有用户存储过程名称)
--打开游标
Open
curStudentFee
--循环并提取记录
Fetch
Next
From
curStudentFee
Into
@result
--取第一条记录存入@result中
While ( @@Fetch_Status=0 )
begin
print
''
''
+@result+
''
''
+
','
;
---处理结果
Fetch
Next
From
curStudentFee
into
@result
----下一条
end
--关闭游标
Close
curStudentFee
--释放游标
Deallocate
curStudentFee
end