尝试从包执行过程时出现权限不足错误
Posted
技术标签:
【中文标题】尝试从包执行过程时出现权限不足错误【英文标题】:Insufficient Priviledges error when trying to execute the procedure from package 【发布时间】:2014-07-09 09:59:09 【问题描述】:第 1 步:我创建了一个包,其中包含创建上下文和为上下文设置值的过程。
create or replace PACKAGE Context_check AS
PROCEDURE set_context_vpd_proc (V_ISID in varchar2);
procedure set_context (v_isid_a in varchar2);
END Context_check;
create or replace PACKAGE BODY Context_check AS
PROCEDURE set_context_vpd_proc (V_ISID in varchar2)
AS
v_STAT VARCHAR2(200);
v_chk varchar2(2000);
BEGIN
DBMS_SESSION.SET_CONTEXT('VPD_CTX', 'ISID', V_ISID );
--v_STAT := '';
EXCEPTION
WHEN NO_DATA_FOUND THEN NULL;
END;
procedure set_context (v_isid_a in varchar2)
as
begin
EXECUTE IMMEDIATE 'CREATE OR REPLACE CONTEXT VPD_CTX using set_context_vpd_proc';
set_context_vpd_proc (v_isid_a);
EXCEPTION
WHEN NO_DATA_FOUND THEN NULL;
end set_context;
END Context_check;
第 2 步:当我尝试执行该过程时出现错误
EXECUTE Context_check.set_context('Ana');
Error starting at line 43 in command:
EXECUTE Context_check.set_context('Ana')
Error report:
ORA-01031: insufficient privileges
ORA-06512: at "SYS.DBMS_SESSION", line 114
ORA-06512: at "SEC_ADMIN.CONTEXT_CHECK", line 8
ORA-06512: at "SEC_ADMIN.CONTEXT_CHECK", line 20
ORA-06512: at line 1
01031. 00000 - "insufficient privileges"
*Cause: An attempt was made to change the current username or password
without the appropriate privilege. This error also occurs if
attempting to install a database without the necessary operating
system privileges.
When Trusted Oracle is configure in DBMS MAC, this error may occur
if the user was granted the necessary privilege at a higher label
than the current login.
*Action: Ask the database administrator to perform the operation or grant
the required privileges.
For Trusted Oracle users getting this error although granted the
the appropriate privilege at a higher label, ask the database
administrator to regrant the privilege at the appropriate label.
我已经提供了该软件包的所有赠款。但我仍然无法执行此过程。
注意:如果我创建与独立程序相同的程序,它可以正常工作并设置上下文。
【问题讨论】:
您是直接向包所有者授予权限,还是仅通过角色授予权限? 使用授予选项将 Context_check 上的所有内容授予 SEC_ADMIN; SEC_ADMIN 是我们创建此包的用户。 虽然是DBMS_SESSION.SET_CONTEXT
调用产生了错误。如何授予SEC_ADMIN
的权限?这是您无权执行的事情,并且通过角色授予您的任何内容,因为您可以在存储过程之外使用它。
【参考方案1】:
您需要使用包创建上下文,而不是使用包内的过程。
代替
EXECUTE IMMEDIATE 'CREATE OR REPLACE CONTEXT VPD_CTX using set_context_vpd_proc';
写
EXECUTE IMMEDIATE 'CREATE OR REPLACE CONTEXT VPD_CTX using Context_check';
【讨论】:
我还发现您需要在一次原子执行中执行该程序和创建块的过程。对我来说,零碎地做它不起作用,我想它不应该。以上是关于尝试从包执行过程时出现权限不足错误的主要内容,如果未能解决你的问题,请参考以下文章
尝试使用 .NET 5.0 Web 应用程序执行存储过程时出现转换错误