-- 游标简单使用
--定义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