这是我的程序。我在其中使用了名为“CUR_TO_COLLECT_DATA”的游标。我还使用了一个名为“VAR_CUR_TO_COLLECT_DATA”的变量,它属于“TBL_TRIAL_BALANCE_REPORT”表类型。
现在我不想使用“VAR_CUR_TO_COLLECT_DATA”变量,而是想使用游标的名称,即“CUR_TO_COLLECT_DATA”代替“VAR_CUR_TO_COLLECT_DATA”变量。
做这个任务可行吗?如果是,那么请帮助如何?
PROCEDURE PR_TRIAL_BALANCEWITHOUTFOR IS
CURSOR CUR_TO_COLLECT_DATA IS(
SELECT NAME, SUM(CREDIT) AS CREDIT, SUM(DEBIT) AS DEBIT
FROM (
SELECT (SELECT GL_NAME
FROM QM_GL
WHERE QM_GL.GL_ID = QT_ACCOUNTING.GL_ID) AS NAME,
DECODE(QT_ACCOUNTING.TRANS_TYPE,
'CR',
(QT_ACCOUNTING.TRANS_AMOUNT),
0.00) AS CREDIT,
DECODE(QT_ACCOUNTING.TRANS_TYPE,
'DR',
(QT_ACCOUNTING.TRANS_AMOUNT),
0.00) AS DEBIT
FROM QT_ACCOUNTING, QM_ACCOUNTING_PERIOD
WHERE QT_ACCOUNTING.VALUE_DATE BETWEEN
QM_ACCOUNTING_PERIOD.PERIODFROM AND
QM_ACCOUNTING_PERIOD.PERIODTO
AND QM_ACCOUNTING_PERIOD.STATUS = 'O'
)
GROUP BY NAME);
VAR_CUR_TO_COLLECT_DATA TBL_TRIAL_BALANCE_REPORT%ROWTYPE;
BEGIN
OPEN CUR_TO_COLLECT_DATA;
LOOP
FETCH CUR_TO_COLLECT_DATA
INTO VAR_CUR_TO_COLLECT_DATA;
IF (VAR_CUR_TO_COLLECT_DATA.CREDIT - VAR_CUR_TO_COLLECT_DATA.DEBIT) > 0 THEN
INSERT INTO TBL_TRIAL_BALANCE_REPORT
VALUES
(VAR_CUR_TO_COLLECT_DATA.NAME,
(VAR_CUR_TO_COLLECT_DATA.CREDIT - VAR_CUR_TO_COLLECT_DATA.DEBIT),
0);
END IF;
IF (VAR_CUR_TO_COLLECT_DATA.DEBIT - VAR_CUR_TO_COLLECT_DATA.CREDIT) > 0 THEN
INSERT INTO TBL_TRIAL_BALANCE_REPORT
VALUES
(VAR_CUR_TO_COLLECT_DATA.NAME,
0,
(VAR_CUR_TO_COLLECT_DATA.DEBIT - VAR_CUR_TO_COLLECT_DATA.CREDIT));
END IF;
EXIT WHEN CUR_TO_COLLECT_DATA%NOTFOUND;
END LOOP;
CLOSE CUR_TO_COLLECT_DATA;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE(SQLERRM);
BEGIN
CLOSE CUR_TO_COLLECT_DATA;
EXCEPTION
WHEN OTHERS THEN
NULL;
END;
END;