DECLARE
@id INT, @value VARCHAR(10);
BEGIN
-- 定义游标.
DECLARE c_test_main CURSOR FAST_FORWARD FOR
SELECT id,valueFROM test_main;
-- 打开游标.
OPEN c_test_main;
WHILE 1=1
BEGIN
-- 填充数据.
FETCH NEXT FROM c_test_main INTO @id, @value;
-- 假如未检索到数据,退出循环.
IF@@fetch_status!= 0 BREAK;
PRINT @value;
END;
-- 关闭游标
CLOSE c_test_main;
-- 释放游标.
DEALLOCATE c_test_main;
END;go