甲骨文程序

发布于 2024-10-27 21:54:21 字数 1592 浏览 2 评论 0原文

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;

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

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 语句时,我没有收到此错误。 请帮我解决这个问题。

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;

On compiling the above function i get the following error

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                                                       

I'm not getting this error when i execute the select statement alone in the cursor.
Please help me to resolve this issue.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

坦然微笑 2024-11-03 21:54:21

您的用户需要被授予 SELECT ON DBA_TAB_COLUMNS 权限。

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

Your user needs to be granted SELECT ON DBA_TAB_COLUMNS.

Note that granting through a role will not work - it needs to be a direct grant to the user for you to create a function/procedure.

秋叶绚丽 2024-11-03 21:54:21

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

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

SQL> set role none;

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

In a definer's rights stored procedure such as the one you are creating, only privileges that are granted directly to the owner of the procedure are considered when resolving object names. Privileges granted through roles are not considered. I would wager that the owner of your procedure has been granted access to the DBA_TAB_COLUMNS view via a role rather than via a direct grant. You would need to ask the DBA to grant access to DBA_TAB_COLUMNS directly to the user that owns your procedure.

You can quickly test whether this is actually the problem you're experiencing. In SQL*Plus, enter the command

SQL> set role none;

and then run your SELECT statement. If you get the same permissions error, then the rpoblem is that you have the grant via a role. Disabling roles means that your interactive session is running with the same privileges that your stored procedure would run with.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文