【SQL开源代码栏目提醒】:网学会员SQL开源代码为您提供实例333利用游标设计带滚动的商品销售数据查询.sql参考,解决您在实例333利用游标设计带滚动的商品销售数据查询.sql学习中工作中的难题,参考学习。
USE db_sql2000
GO
SELECT 客户全称, 商品名称 FROM 销售表 where 数量>300
ORDER BY 客户全称, 商品名称
-- 声明游标
DECLARE authors_cursor SCROLL CURSOR FOR
SELECT 客户全称, 商品名称 FROM 销售表 where 数量>300
ORDER BY 客户全称, 商品名称
--打开游标
OPEN authors_cursor
-- Fetch the last row in the cursor.
FETCH LAST FROM authors_cursor
-- Fetch the row immediately prior to the current row in the cursor.
FETCH PRIOR FROM authors_cursor
-- Fetch the second row in the cursor.
FETCH ABSOLUTE 2 FROM authors_cursor
-- Fetch the row that is three rows after the current row.
FETCH RELATIVE 3 FROM authors_cursor
-- Fetch the row that is two rows prior to the current row.
FETCH RELATIVE -2 FROM authors_cursor
CLOSE authors_cursor --关闭游标
DEALLOCATE authors_cursor --释放游标
GO