简体   繁体   English

多模式选择语句在PL / SQL过程中不起作用?

[英]Multi-schema select statement doesn't work in PL/SQL procedure?

I'm trying to create a procedure to run multiple PL/SQL statements, but I haven't gotten very far. 我正在尝试创建一个过程来运行多个PL / SQL语句,但是距离还很远。 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. 如果我在某个过程之外运行select语句,则它运行良好,但是如果我尝试在一个过程中执行它,则它找不到shttran表。 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;

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. 问题很可能是拥有存储过程REGREPORTUSER的用户可以通过角色而不是直接授予访问表saturn.shttran权限。 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. 您可以通过禁用SQL * Plus会话中的角色来验证这实际上是问题。 If you run the command 如果运行命令

SQL> set role none;

and then try to execute the SQL statement, you should get the same error. 然后尝试执行SQL语句,应该得到相同的错误。 In order to fix the problem, you need to give the grant directly 为了解决该问题,您需要直接给予补助

GRANT SELECT ON saturn.shttran
   TO REGREPORTUSER

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM