2016-11-24 84 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

相關問題