我做了一个如下所示的程序我想获取游标值并从其他循环中提取这些值告诉我这里最好的方法是我的代码
CREATE OR REPLACE PROCEDURE TEST (P_EMP_ID NUMBER,
TRIGER_BY VARCHAR2)
AS
CURSOR TO_HOD
IS
SELECT EMP.EMPLOYEE_CODE,
EMP.EMP_NAME,
APR.LEFT_DT,
APR.RESIGN_TYPE
FROM FSC_APPROVAL APR, CHR_ALL_EMPLOYEE_BI_V EMP
WHERE APR.HOD_APPR = 'Y'
AND APR.ZONE_HD_APPR IS NULL
AND EMP.EMPLOYEE_ID = APR.EMP_ID;
CURSOR TO_ZONE
IS
SELECT EMP.EMPLOYEE_CODE,
EMP.EMP_NAME,
APR.LEFT_DT,
APR.RESIGN_TYPE
FROM FSC_APPROVAL APR, CHR_ALL_EMPLOYEE_BI_V EMP
WHERE APR.HOD_APPR = 'Y'
AND APR.ZONE_HD_APPR = 'Y'
AND APR.TIM_OFC_APPR IS NULL
AND EMP.EMPLOYEE_ID = APR.EMP_ID;
CUR_VAL TO_HOD%ROWTYPE;
CUR_VAL_FOR_LOOP TO_HOD%ROWTYPE;
这里的程序开始
BEGIN
IF TRIGER_BY = 'HOD'
THEN
OPEN TO_HOD;
LOOP
FETCH TO_HOD INTO CUR_VAL;
EXIT WHEN TO_HOD%NOTFOUND;
END LOOP;
ELSIF TRIGER_BY = 'ZONE'
THEN
OPEN TO_ZONE;
LOOP
FETCH TO_ZONE INTO CUR_VAL;
EXIT WHEN TO_ZONE%NOTFOUND;
END LOOP;
END IF;
在上面的代码中只需获取我的数据并输入 cur_val 即%rowtype 之后,我在新循环中获取这些值,但它没有意义并显示错误 PLS-00456:item' CUR_VAL'不是光标
LOOP
***FETCH CUR_VAL INTO CUR_VAL_FOR_LOOP;***
DBMS_OUTPUT.PUT_LINE (CUR_VAL_FOR_LOOP.EMPLOYEE_CODE);
END LOOP;
END;
/
我在这一行上遇到错误FETCH CUR_VAL INTO CUR_VAL_FOR_LOOP;
如果你有更好的选择,请指导我如何按照我的意愿制作这个程序然后如果你对我的问题有进一步的询问我热烈欢迎,那么我将在这里描述你
答案 0 :(得分:1)
为什么使用两个变量?你可以做得更短(未经测试):
CURSOR TO_ALL(hd APR.ZONE_HD_APPR%TYPE) IS
SELECT EMP.EMPLOYEE_CODE,
EMP.EMP_NAME,
APR.LEFT_DT,
APR.RESIGN_TYPE
FROM FSC_APPROVAL APR,
JOIN CHR_ALL_EMPLOYEE_BI_V EMP ON EMP.EMPLOYEE_ID = APR.EMP_ID
WHERE APR.HOD_APPR = 'Y'
AND NVL(APR.ZONE_HD_APPR, 'NULL') = NVL(hd, 'NULL')
AND EMP.EMPLOYEE_ID = APR.EMP_ID;
CUR_VAL TO_ALL%ROWTYPE;
BEGIN
OPEN TO_ALL(CASE TRIGER_BY WHEN 'HOD' THEN 'NULL' ELSE 'Y');
LOOP
FETCH TO_ALL INTO CUR_VAL;
...
EXIT WHEN TO_ALL%NOTFOUND;
END LOOP;
END;