本文介绍了SQL Server 2005上的游标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的先生
请通过示例解释Sql Server2005中的游标
和使用游标
我需要详细说明游标
我们可以在没有创建过程的情况下使用游标吗?
请帮助我对我很重要
感谢和问候
JAYA
Dear Sir
Please Explained About Cursors in Sql Server2005 with Example
and Use Of the Cursors
I need to Detail Expalanation of Cursors
Can we use Cursors with out create Procedure
Plz Help me very imp to me
Thanks And Regards
JAYA
推荐答案
DECLARE @TableName VARCHAR(2000)
DECLARE db CURSOR FOR
SELECT name
FROM sysobject
WHERE xtype = 'u'
OPEN DB
FETCH NEXT FROM db INTO @TableName
WHILE @@FETCH_STATUS = 0
BEGIN
PRINT @TableName
FETCH NEXT FROM db INTO @TableName
END
CLOSE db
DEALLOCATE db
我们可以在没有创建过程的情况下使用游标吗-是
Can we use Cursors with out create Procedure - YES
Declare @row int
Declare @CODE varchar(10)
Declare @VN varchar(50)
Select @row = acode from Tblmst_Serial
DECLARE CU CURSOR FOR SELECT TYP,VNAME FROM Tblmst_Serial
OPEN CU
while(@row >0) // alternative we can Also Use here "While(@@fetch_status<>0)"
begin
fetch next from CU into @CODE,@VN
print @CODE
print @VN
Set @row =@row -1
end
Close CU
Deallocate CU
这篇关于SQL Server 2005上的游标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!