Oracle Apex ORA-14551:无法在查询中执行 DML 操作提示

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

我使用 APEX 4.2。

我有一个包含此查询的交互式报告:

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

函数 function_check_user() returns 1 如果具有角色 'ADMIN' 的用户可以显示结果询问。我正在使用 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;

问题: 我使用查询设置了无吸引力的报告,并尝试在我的应用程序中 运行 它。我有这个错误:

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()的使用有问题吗?

谢谢

您可以通过在函数中声明 pragma 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;