【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成功
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值