oracle触发器执行DBMS_AQ获取的权限错误不足

时间:2012-12-11 17:49:59

标签: oracle11g oracle-aq

我正在使用oracle 11.2。

数据库用户:

  1. AQADM :用户拥有队列,并且 AQ_ADMINISTRATOR_ROLE
  2. SCOTT :jms用户,具有以下权限。
  3. 我有以下存储过程,编译好了。它是从表上的触发器调用的。

    CREATE OR REPLACE PROCEDURE scott.PROC_JMS_ENQUEUE (NAME      VARCHAR,
                                              MESSAGE      IN VARCHAR)
    AS
      msg                  SYS.AQ$_JMS_TEXT_MESSAGE;
      queue_options        DBMS_AQ.ENQUEUE_OPTIONS_T;
      msg_props            DBMS_AQ.MESSAGE_PROPERTIES_T;
      msg_id               RAW (16);
      no_consumers_error   EXCEPTION;
      PRAGMA EXCEPTION_INIT (no_consumers_error, -24033);
    BEGIN
    -- Ensure what is sent will be a JMS message
     msg := SYS.AQ$_JMS_TEXT_MESSAGE.CONSTRUCT ();
     msg.set_text (MESSAGE);
    
     --ENQUEUE
     DBMS_AQ.ENQUEUE (queue_name           => 'aqadm.my_queue',
                    enqueue_options      => queue_options,
                    message_properties   => msg_props,
                    payload              => msg,
                    msgid                => msg_id);
      -- Without the following, the procedure will die if none
      -- Is listening for cache control
     EXCEPTION
     WHEN no_consumers_error
     THEN
      -- Output it in case, but otherwise swallow
      DBMS_OUTPUT.PUT_LINE (
         'No interested parties are listening to messages');
     END;
     /
    

    我跟随GRANT给用户

    GRANT EXECUTE ON AQ_USER_ROLE TO scott;
    GRANT EXECUTE ON SYS.DBMS_AQ TO scott;
    GRANT EXECUTE ON SYS.DBMS_AQIN TO scott;
    --GRANT EXECUTE ON SYS.DBMS_AQJMS_INTERNAL TO scott;
    --GRANT EXECUTE ON SYS.DBMS_TRANSFORM TO scott;
    GRANT EXECUTE ANY PROCEDURE TO scott;
    

    当我执行上面的存储过程,或更新触发触发代码的表时,我收到以下错误:

    exec PROC_JMS_ENQUEUE('Test Message','Dam');
    
    ORA-01031: insufficient privileges
    ORA-06512: at "SYS.DBMS_AQ", line 169
    ORA-06512: at "SCOTT.PROC_JMS_ENQUEUE", line 19
    ORA-06512: at line 1
    

    修改 这是特权视图,所有都被授予SYS作为SYSDBA enter image description here enter image description here

2 个答案:

答案 0 :(得分:2)

当我授予以下

时,它有效
GRANT ENQUEUE ANY QUEUE TO SCOTT;

Oracle sucks on one consolidated documentation!

另外,GRANT必须“直接”而不是通过“角色”才能通过PL / SQL触发器或程序执行!!!!!

答案 1 :(得分:0)

通常当某些代码在从sqlplus执行时为你工作但从触发器执行时不起作用是由同样的原因引起的:

用户有权限。直接授予(Type = Priviledge)或间接授予(Type = Role)。当代码作为触发器执行时,只有直接私有。可用。即。你没有AQ_USER_ROLE的任何补助金。检查AQ_USER_ROLE定义(我认为此角色无论如何都被弃用)并将这些权限直接授予SCOTT。