[讨论]sql游标的使用
大家对sql中的游标使用的多吗?它的作用是什么?有什么好处呢?
USE pubs
GO
CREATE PROCEDURE OpenCrsr AS
DECLARE SampleCrsr CURSOR FOR
SELECT au_lname
FROM authors
WHERE au_lname LIKE 'S%'
OPEN SampleCrsr
GO
CREATE PROCEDURE ReadCrsr AS
FETCH NEXT FROM SampleCrsr
WHILE (@@FETCH_STATUS <> -1)
BEGIN
FETCH NEXT FROM SampleCrsr
END
GO
EXEC OpenCrsr /* DECLARES and OPENS SampleCrsr. */
GO
EXEC ReadCrsr /* Fetches the rows from SampleCrsr. */
GO
CLOSE SampleCrsr
GO
DEALLOCATE SampleCrsr
GO