写一段游标的sql语句
时间: 2023-04-03 15:00:56 浏览: 102
SQL游标实例
以下是一段游标的 SQL 语句:
DECLARE @id INT
DECLARE @name VARCHAR(50)
DECLARE cursor_name CURSOR FOR
SELECT id, name FROM table_name
OPEN cursor_name
FETCH NEXT FROM cursor_name INTO @id, @name
WHILE @@FETCH_STATUS =
BEGIN
-- 在这里可以对每一行数据进行操作
PRINT 'ID: ' + CAST(@id AS VARCHAR(10)) + ', Name: ' + @name
FETCH NEXT FROM cursor_name INTO @id, @name
END
CLOSE cursor_name
DEALLOCATE cursor_name
阅读全文