【Oracle】ORA-30553: 函數不確定的解決辦法

 如果需要創建基於自定義函數的索引,那麼我們需要指定deterministic參數,在函數建立的時候指定該參數問題可解決。

SQL> CREATE OR REPLACE FUNCTION f_xifenfei (itime DATE)
  RETURN DATE
  IS
  4  otime DATE;
  BEGIN
  6    otime:=NVL(itime,SYSDATE);
  7    RETURN otime;
  END;
  9  /
Function created.
--想採用自定義函數屏蔽掉sysdate在創建index時候的影響
SQL>  create index in_t_xifenfei on t_xifenfei (f_xifenfei(intime)) online nologging;
create index in_t_xifenfei on t_xifenfei (f_xifenfei(intime)) online nologging
                                           *
ERROR at line 1:
ORA-30553: The function is not deterministic
SQL> !oerr ora 30553
30553, 00000, "The function is not deterministic"
// *Cause:  The function on which the index is defined is not deterministic
// *Action: If the function is deterministic, mark it DETERMINISTIC.  If it
//          is not deterministic (it depends on package state, database state,
//          current time, or anything other than the function inputs) then
//          do not create the index.  The values returned by a deterministic
//          function should not change even when the function is rewritten or
//          recompiled.
--因爲函數缺少deterministic不能使用於index上
SQL> CREATE OR REPLACE FUNCTION f_xifenfei (itime DATE)
  RETURN DATE deterministic
  IS
  4  otime DATE;
  BEGIN
  6    otime:=NVL(itime,SYSDATE);
  7    RETURN otime;
  END;
  9  /
Function created.
SQL> create index in_t_xifenfei on t_xifenfei (f_xifenfei(intime)) online nologging;
Index created.
--創建函數index成功
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章