Oracle程序

Oracle程序,oracle,plsql,Oracle,Plsql,编译上述函数时,我得到以下错误 create or replace function gen.sample_func(owner varchar2) return varchar2 as data_t varchar2(10); cursor cur is select data_type from SYS.DBA_TAB_COLUMNS; begin open cur; dbms_output.p

编译上述函数时,我得到以下错误

create or replace function gen.sample_func(owner varchar2) return varchar2 
    as 
     data_t varchar2(10); 
      cursor cur is   select  data_type  from  SYS.DBA_TAB_COLUMNS;
      begin  
        open cur;
          dbms_output.put_line('Done'); 
        close cur; 
        return data_t;  
    end sample_func;
当我在游标中单独执行
select
语句时,我没有得到这个错误。
请帮助我解决此问题。

在定义者权限存储过程(如您正在创建的存储过程)中,解析对象名称时只考虑直接授予过程所有者的权限。不考虑通过角色授予的特权。我敢打赌,您的过程的所有者已被授予通过角色而非直接授权访问
DBA\u TAB\u列
视图的权限。您需要请求DBA将对
DBA\u TAB\u列的访问权直接授予拥有您的过程的用户

您可以快速测试这是否确实是您遇到的问题。在SQL*Plus中,输入以下命令

Warning: compiled but with compilation errors
Errors for FUNCTION sample_func

LINE/COL                                                                        
--------------------------------------------------------------------------------
ERROR                                                                           
--------------------------------------------------------------------------------
4/8                                                                             
PLS-00201: identifier 'DBA_TAB_COLUMNS' must be declared                        

4/8                                                                             
PL/SQL: Item ignored                                                            

7/15                                                                            
PLS-00320: the declaration of the type of this expression is incomplete or malfo
rmed                                                                            

7/8                                                                             
PL/SQL: Statement ignored                                                       

然后运行SELECT语句。如果您收到相同的权限错误,则RPO问题是您通过角色获得了授权。禁用角色意味着您的交互式会话正在以与存储过程运行时相同的权限运行。

您的用户需要被授予在DBA\u选项卡上选择列的权限

请注意,通过角色授予将不起作用-创建函数/过程需要直接授予用户

SQL> set role none;