首页 > 解决方案 > 如何在与另一个不同的架构中调用不同包中的过程

问题描述

我想在与当前运行的模式和包不同的一个包中调用一个模式中声明的过程

还有一个几乎相关的问题,但我的不同之处在于被调用的过程在另一个模式和包中,而不仅仅是另一个包。

declare 
  l_hub_msg varchar(1000);
  l_query varchar(1000);
begin
  -- Call a procedure in the same schema. Problem is not here 
  l_query := 'pkg_hub.loadFlatTable' ;
  execute immediate 'l_query' into l_hub_msg;

  if l_hub_msg is not null and length(l_hub_portfolio_msg) > 0 then


    -- The following line gives me an PLS-00201: identifier 'PKG_EMAIL_PAGE.SENDMSG' must be declared
    PKG_EMAIL_PAGE.SENDMSG('Message', 'FromUser@mycompany.com','ToUser@mycompany.com','ToUser@mycompany.com'
                           'Content',
                           'someuser@mycompany.com');
  end if;
end;

将此过程视为在模式 SCHEMA1 下运行,而 PKG_EMAIL_PAGE 是存在于模式 SCHEMA2 下的包。

使用 SQL Developer 菜单选项,据说我将 PKG_EMAIL_PAGE.SENDMSG 的 EXECUTE 访问权限授予 SCHEMA2。也就是说,它说它成功了。

虽然我无法让它工作:

GRANT EXECUTE ON PKG_EMAIL_PAGE.SENDMSG to SC_REPORT_NEW;

因为它说

QL Error: ORA-04042: procedure, function, package, or package body does not exist
04042. 00000 -  "procedure, function, package, or package body does not exist"
*Cause:    Attempt to access a procedure, function, package, or package body
           that does not exist.
*Action:   Make sure the name is correct.

感谢您的阅读;樵夫

标签: plsqlplsql-package

解决方案


GRANT 不是针对包中的单个方法,而是针对整个包,并且它们不是授予另一个包而是授予另一个用户。

schema2需要授予:

GRANT EXECUTE ON pkg_email_page TO schema1

然后schema1可以调用此过程,但需要在调用中指定架构:

BEGIN
  schema2.pkg_email_page.sendmsg( ... );
END;

推荐阅读