SQL Server 2005上的游标 [英] Cursors On Sql Server 2005
本文介绍了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
推荐答案
http://msdn. microsoft.com/en-us/library/ms180169.aspx [ ^ ]
http://www.sqlteam.com/article/cursors-an-overview [ ^ ]
http://sqlserverpedia.com/wiki/Built-in_Functions_-__Cursor_Functions [
http://msdn.microsoft.com/en-us/library/ms180169.aspx[^]
http://www.sqlteam.com/article/cursors-an-overview[^]
http://sqlserverpedia.com/wiki/Built-in_Functions_-_Cursor_Functions[^]
Go through these links
Codehelper ,给出了不错的链接,您也应该阅读
首先,您需要意识到的是cursors
可能是一项昂贵的操作,应尽可能避免使用.
游标的示例如下
Codehelper, has given great links that you should read also
Firstly the thing that you need to be aware of is thatcursors
can be an expensive operation and should be avoided where possible.
An example Cursor is as follows
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
1.出于定义目的:- ^ ]
2.Cursor基本上用于PL/SQL,即使我们也可以在存储过程中使用游标,也可以在没有存储过程的情况下使用游标,这取决于条件.
Synax和游标示例:-
1.For Defination Purpose :- http://sqlserverpedia.com/wiki/Built-in_Functions_-_Cursor_Functions[^]
2.Cursor is Basically Used for PL/SQL Even We Can Also Used Cursor in Stored Procedure OR Without Stored procedure it''s Depands on Condition.
Synax and Example of Cursor :-
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上的游标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文