Domanda

I'm trying to create a procedure to run multiple PL/SQL statements, but I haven't gotten very far. The select statement works fine if I run it out of a procedure, but if I try to execute it inside one -- it can't find the shttran table. I'm guessing it might be a schema issue, but I have no idea how-to correct. Ideas?

CREATE OR REPLACE PROCEDURE REGREPORTUSER.findUnsent
IS
BEGIN
   INSERT INTO regreportuser.maltran (maltran.maltran_key,
                                      maltran.maltran_sent)
      SELECT shttran.shttran_id || shttran.shttran_seq_no AS maltran_key,
             'No' AS maltran_sent
        FROM saturn.shttran -- This is the table it can't find
       WHERE     TO_DATE (shttran.shttran_activity_date) > SYSDATE - 14
             AND shttran.shttran_user = 'WWW2_USER'
             AND shttran.shttran_id || shttran.shttran_seq_no NOT IN
                    (SELECT maltran.maltran_key FROM regreportuser.maltran);
END findUnsent;
È stato utile?

Soluzione

Most likely, the problem is that the user that owns the stored procedure, REGREPORTUSER has access to the table saturn.shttran via a role rather than as a direct grant. A definer's rights stored procedure cannot use privileges that are granted to a definer via a role. It can only use privileges granted directly.

You can verify that this is, in fact, the problem by disabling roles in your SQL*Plus session. If you run the command

SQL> set role none;

and then try to execute the SQL statement, you should get the same error. In order to fix the problem, you need to give the grant directly

GRANT SELECT ON saturn.shttran
   TO REGREPORTUSER
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top