title: How to know if a user has a privilege on Object?
body: <p>I would like to know if a user has a privilege on an object or not.</p>
  
  <p>I'm working on SQL Developer.</p>
  
  <p>When I query manually the table <strong>DBA_TAB_PRIVS</strong>, I get all the information needed.</p>
  
  <p>However, I need this information to be used in some triggers and functions.</p>
  
  <p>So, I'm writing PL/SQL function that will return 1 if a role has the privilege and 0 otherwise.</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION HAS_PRIVILEGE_ON_OBJECT(rolename      IN VARCHAR2,
                                                     objectname    IN VARCHAR2,
                                                     objectowner   IN VARCHAR2,
                                                     privilegename IN VARCHAR2)
    RETURN NUMBER
  AS
    output NUMBER;
    BEGIN
  
      SELECT count(*) INTO output
        FROM dba_tab_privs
       WHERE grantee = rolename
         AND owner = objectowner
         AND table_name = objectname
         AND privilege = privilegename;
  
      IF output &gt; 0 THEN
        RETURN 1;
      ELSE
        RETURN 0;
      END IF;
    END has_privilege_on_object;
  </code></pre>
  
  <p>The function doesn't compile and says : </p>
  
  <blockquote>
    <p>ORA 942 : table or view does not exist.</p>
  </blockquote>
  
  <p>The user connected has access to the view DBA_TAB_PRIVS since I can query it, but when trying to automate it using a function. It doesn't work.</p>
  
  <p>Any ideas please?</p>