光标在函数中出错

Error with cursor in function

我需要在一个函数中创建 Cursor,但是当我执行一个函数时,我得到一个错误,即 "insufficient privileges" on the table in the Cursor,this table is exist在另一个模式上,我拥有所有特权,甚至 select。在我的用户上也有此 table 的同义词,当我在 Cursor 之外执行此查询时,它可以正常工作。 我需要你的帮助。 最好的问候

这是代码:

CREATE OR REPLACE Function cursor_test_func
    ( temp IN number )
    RETURN varchar2
IS
    total_val number(6);

    cursor brn_code_curs is
     SELECT code_brn
     FROM dbschema.branche;

BEGIN
    total_val := 0;
    FOR brn_rec in brn_code_curs
    LOOP
        DBMS_OUTPUT.PUT_LINE ('code = ' || brn_rec.code_brn);
    END LOOP;
    RETURN total_val;
END;

如果授权可通过角色获得但未明确提供给您的用户,则通常会发生这种情况。要允许使用 PL/SQL 中的对象,您的用户需要获得必要的授权。

更多信息请见 AskTom