use Test
---定义后直接赋值
Declare test_Cursor CURSOR FORWARD_ONLY FOR
SELECT * FROM [Test].[dbo].[TrackLog]
----先定义后赋值
Declare @TEST_Cursor2 CURSOR
SET @TEST_Cursor2= CURSOR FOR
SELECT * FROM [Test].[dbo].[TrackLog]
------全局游标 跨LOCAL
DECLARE test_Cursor3 CURSOR GLOBAL SCROLL FOR
SELECT fullname FROM [Test].[dbo].[TrackLog]
------局部游标,跨Local
DECLARE test_Cursor4 CURSOR LOCAL FOR
SELECT * FROM [Test].[dbo].[TrackLog]
DEALLOCATE test_Cursor3
DEALLOCATE test_Cursor
OPEN test_Cursor3;
DECLARE @C NVarchar(100)
FETCH LAST FROM test_Cursor3 into @c
print @c
FETCH PRIOR FROM test_Cursor3 into @c
print @c
FETCH NEXT FROM test_Cursor3 into @c
print @c
FETCH FIRST FROM test_Cursor3 into @c
print @c
FETCH NEXT FROM test_Cursor3 into @c
print @c
FETCH ABSOLUTE 2 FROM test_Cursor3 into @c
print @c
FETCH RELATIVE 2 FROM TEST_CURSOR3 into @c
print @c
DEALLOCATE CursorTest_Scroll
DECLARE CursorTest_Scroll CURSOR SCROLL FOR
SELECT * FROM [Test].[dbo].[TrackLog]
OPEN CursorTest_Scroll
DECLARE @ID int
Declare @Fullname nvarchar(100)
Declare @METHODNAME nvarchar(100)
Declare @EXECUTETIME nvarchar(100)
Declare @ROWDATE nvarchar(100)
Declare @STATUS nvarchar(100)
Declare @MESSAGE nvarchar(100)
Declare @CLIENTIP nvarchar(100)
Declare @CITYCODE nvarchar(100)
WHILE @@FETCH_STATUS=0
BEGIN
PRINT @ID
PRINT @FULLNAME
PRINT @METHODNAME
FETCH NEXT FROM CursorTest_Scroll INTO @ID,@FULLNAME,@METHODNAME,@EXECUTETIME,@ROWDATE,@STATUS,@MESSAGE,@CLIENTIP,@CITYCODE
END
CLOSE CursorTest_Scroll
DEALLOCATE CursorTest_Scroll
游标打开
OPEN CursorTest_Scroll
游标关闭
CLOSE CursorTest_Scroll
游标释放DEALLOCATE CursorTest_Scroll