游标简单使用
-- 游标简单使用
--定义DEP_CURSOR
DECLARE DEP_CURSOR CURSOR
FOR
SELECT DepID,DepName FROM Dep
--打开
OPEN DEP_CURSOR
DECLARE @P_DepID VARCHAR(10),@P_DepName VARCHAR(10)
FETCH NEXT FROM DEP_CURSOR
INTO @P_DepID,@P_DepName
--循环
WHILE (@@FETCH_STATUS <> -1)
BEGIN
IF (@@FETCH_STATUS <> -2)
BEGIN
PRINT @P_DepID +'-'+@P_DepName
END
FETCH NEXT FROM DEP_CURSOR INTO @P_DepID,@P_DepName
END
--关闭
CLOSE DEP_CURSOR
--释放
DEALLOCATE DEP_CURSOR
posted on 2007-09-14 16:12 freeliver54 阅读(346) 评论(1) 编辑 收藏 举报