为什么我得到" PLS-00405:在此上下文中不允许使用子查询"错误?

时间:2014-07-24 16:14:00

标签: sql plsql subquery

对于PL / SQL,我是新手。我有以下PL / SQL代码块:

FUNCTION  evaluate(p_sid IN NUMBER, p_min_len IN NUMBER, p_max_len IN NUMBER) RETURN VARCHAR2
IS
    v_res VARCHAR2(255);
BEGIN
    v_res := evaluate_batch(CURSOR(SELECT sid, stext FROM maintable WHERE sid = p_sid), p_min_len, p_max_len);

    RETURN v_res;

END eval_ocr_quality;

,其中

TYPE text_rec_t IS RECORD (
        rec_id NUMBER,
        text CLOB);
TYPE text_rec_cur_t IS REF CURSOR RETURN text_rec_t;

FUNCTION  evaluate(p_sid IN NUMBER, p_min_len IN NUMBER := 3, p_max_len IN NUMBER := 3) RETURN VARCHAR2;

FUNCTION  evaluate_batch(p_cur IN text_rec_cur_t, p_min_len IN NUMBER := 3, p_max_len IN NUMBER := 3) RETURN VARCHAR2;

我在PLS-00405: subquery not allowed in this context

时出现v_res := evaluate_batch错误

我做错了什么?

1 个答案:

答案 0 :(得分:1)

单独打开光标并将其传递到:

FUNCTION  evaluate(p_sid IN NUMBER, p_min_len IN NUMBER, p_max_len IN NUMBER) RETURN VARCHAR2
IS
    v_res VARCHAR2(255);
    c     TEXT_REC_CUR_T;
BEGIN
    OPEN c FOR SELECT TEXT_REC_T(sid, stext) FROM maintable WHERE sid = p_sid;

    v_res := evaluate_batch(c, p_min_len, p_max_len);

    -- May need to close cursor c here if not closed in evaluate_batch

    RETURN v_res;
END eval_ocr_quality;

分享并享受。