SQL CURSOR的创建
来源:未知 责任编辑:责任编辑 发表时间:2013-12-18 11:36 点击:次
SQL CURSOR的使用
/*
@@FETCH_STATUS =0 FETCH 语句成功
@@FETCH_STATUS =-1 FETCH 语句失败或此行不在结果集中
@@FETCH_STATUS =-2 被提取的行不存在 www.2cto.com
*/
/****************************************
AUTHOR: AWIN
FUNCTION: 创建游标
DATE: 2012-04-01
****************************************/
--创建测试表
CREATE TABLE GHS
(GHSDM NVARCHAR(20),
GHSMC NVARCHAR(30))
--增加测试数据
INSERT INTO GHS
SELECT 'G10001','随意市场' UNION ALL
SELECT 'G10002','百成汇服饰' UNION ALL
SELECT 'G10003','冠姿服饰' UNION ALL
SELECT 'G10004','霞湖世家' UNION ALL
SELECT 'G10005','凯文威特服饰' UNION ALL
SELECT 'G10006','柏堡龙' UNION ALL
SELECT 'G10007','南通凯荣服饰' UNION ALL
SELECT 'G10008','易臣非' UNION ALL
SELECT 'G10009','嘉兴纽纳斯' UNION ALL
SELECT 'G10010','百马针织'
--创建游标
DECLARE @GHSDM NVARCHAR(20)
,@GHSMC NVARCHAR(30)
DECLARE cursonGhs CURSOR
FOR
SELECT GHSDM,GHSMC
FROM GHS
OPEN cursonGhs
FETCH NEXT FROM cursonGhs
INTO @GHSDM,@GHSMC
WHILE @@FETCH_STATUS=0
BEGIN www.2cto.com
IF(@GHSDM='G10002' OR @GHSDM='G10006')
BEGIN
PRINT @GHSDM+','+@GHSMC
END
FETCH NEXT FROM cursonGhs
INTO @GHSDM,@GHSMC
END
CLOSE cursonGhs
DEALLOCATE cursonGhs
--删除测试表
DROP TABLE GHS
摘自 awinliu的专栏
相关新闻>>
最新推荐更多>>>
- 发表评论
-
- 最新评论 更多>>