PLSQL查看sys_refcursor的输出

时间:2013-05-08 15:36:48

标签: plsql toad

我正在使用TOAD for Oracle 11,而且我对SQL很新。我写了一个proc,现在正试图测试并查看其输出。我写了以下块:

DECLARE
    cur_test SYS_REFCURSOR;

    type t_row is record(psh_code varchar2(20) , pattr_end_date varchar2(20),     pperf_gross varchar2(20));
    r_test t_row;
BEGIN

    procPerfTR(xxx-xxxx', 'xxxxxxx', 'xxxxxxx', 'xxxxxx', :cur_test);
    LOOP
        FETCH cur_test INTO r_test;

        EXIT WHEN cur_test%NOTFOUND;
    END LOOP;

    CLOSE cur_test;
END;
/

但是,我在LOOP行上出现以下错误

ORA-01001:光标无效

错误在第10行,即其上有“LOOP”的行

我的过程看起来像这样

CREATE OR REPLACE PROCEDURE procPerfTR

(
    paramPortfCode VARCHAR2, 
    paramEndDate VARCHAR2, 
    paramShare VARCHAR2,
    paramFreq VARCHAR2,

    O_cursorPerf out SYS_REFCURSOR
)

IS

    I_cursorPerf SYS_REFCURSOR;

BEGIN

    OPEN I_cursorPerf FOR
    SELECT PS.PSH_CODE, PP.PATTR_END_DATE, PP.PPERF_GROSS
    FROM
        PORTFOLIO_PERFORMANCES PP
        INNER JOIN PORTF_SHARE PS ON PS.PORTF_SHARE_ID = PP.PORTF_SHARE_ID
        INNER JOIN PORTFOLIO P ON P.PORTF_ID = PS.PORTF_ID
        INNER JOIN T_FREQUENCY TF ON TF.FREQUENCY_ID = PP.FREQUENCY_ID
    WHERE
        P.PORTF_CODE = paramPortfCode
        AND PP.PATTR_CALCUL_DATE = PP.PATTR_END_DATE
        AND PP.PATTR_END_DATE = paramEndDate
        AND TF.EXT_CODE = paramFreq
        AND PS.PSH_CODE LIKE
            (CASE 
                WHEN paramShare = 'xxxx' THEN '%xxx'
                WHEN paramShare = 'xxxx' THEN '%xxx'
            END);

    O_cursorPerf:=I_cursorPerf;

END;
/

1 个答案:

答案 0 :(得分:0)

在proc调用中,不要在光标名称前放置冒号。它应该看起来像

procPerfTR('xxx-xxxx', 'xxxxxxx', 'xxxxxxx', 'xxxxxx', cur_test);

(另请注意,我在第一个参数的开头添加了一个单引号,我没有把它作为一个简单的拼写错误)。

分享并享受。