2016-11-24 86 views
0

我使用APEX 4.2。Oracle Apex ORA-14551:无法在查询中执行DML操作提示

我有一个交互式报表与此查询:

select col1, col2, col3, col4 
    from MyTable 
    where function_check_user('ADMIN'); 

功能function_check_user()返回1,如果用户,谁拥有的角色“管理”,可以显示查询的结果。我使用的是APEX程序apex_util.public_check_authorization()

create or replace FUNCTION function_check_user 
(
    xrole VARCHAR2 
) 
return integer IS 
xcheck BOOLEAN; 

begin 
    xcheck:= apex_util.public_check_authorization(xrole); 
    if xcheck then 
    return 1; 
    end if; 
    return 0; 
end; 

问题: 我建立与查询inetractive报告,并尝试在我的应用程序运行。我有这个错误:

Oracle Apex ORA-14551: cannot perform a DML operation inside a query tips. 

它的工作原理,当我使用的查询,而无需在where子句中的功能:

select col1, col2, col3, col4 
from MyTable; 

是否有与使用过程apex_util.public_check_authorization的问题()

感谢

+0

是的,看起来像它。当您尝试在包含DML语句(即INSERT/UPDATE/DELETE/MERGE)的SQL语句中使用函数时,会发生该错误。你也许可以为你的函数添加一个pragma autonomous_transaction,或者[Kishore的答案在这里](http://apps2fusion.com/at/kr/399-security-using-authorization-in-apex#kmt-9271)可能有帮助? – Boneist

+0

但是我的函数中没有DML语句? –

+0

不在您的函数中,但它看起来像在apex_util.public_check_authorization中。我敢打赌,如果你将函数调用出来,它会起作用。 – Boneist

回答

1

您可以通过在函数声明编译AUTONOMOUS_TRANSACTION解决它。

create or replace FUNCTION function_check_user 
(
    xrole VARCHAR2 
) 
return integer IS 
pragma autonomous_transaction; 
xcheck BOOLEAN; 

begin 
    xcheck:= apex_util.public_check_authorization(xrole); 
    rollback; 
    if xcheck then 
    return 1; 
    end if; 
    return 0; 
end; 
+0

一个有趣的解决方法... – Scott

相关问题