ORA-00942: table or view does not exist (works when a separate sql, but does not work inside a oracle function)

后端 未结 5 1869
隐瞒了意图╮
隐瞒了意图╮ 2020-12-06 04:03

When I have a sql statement like select * from table1, it works great, but as soon as I put it into a function, I get:

ORA-00942: table or view          


        
5条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-06 04:43

    There's a strong chance that the privileges to select from table1 have been granted to a role, and the role has been granted to you. Privileges granted to a role are not available to PL/SQL written by a user, even if the user has been granted the role.

    You see this a lot for users that have been granted the dba role on objects owned by sys. A user with dba role will be able to, say, SELECT * from V$SESSION, but will not be able to write a function that includes SELECT * FROM V$SESSION.

    The fix is to grant explicit permissions on the object in question to the user directly, for example, in the case above, the SYS user has to GRANT SELECT ON V_$SESSION TO MyUser;

提交回复
热议问题