函数索引 ORA-30553: The function is not deterministic 解决方法

本文介绍了解决在Oracle数据库中创建基于自定义函数的索引时遇到的ORA-30553错误的方法。通过确保函数确定性并在创建函数时明确声明,可以成功建立索引。

建函数索引的时候报错:ORA-30553: The function is not deterministic 这个函数是自定义的。

SQL>create index mobileIndex on mobile(getmobilearea (callerno));

Google 一下:

ORA-30553:

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参数,在创建函数索引,就没有问题了

CREATE OR REPLACE FUNCTION ICD.getmobilearea (mobileno VARCHAR2)

   RETURN VARCHAR2 deterministic

IS

   s   VARCHAR2 (20);

   i   INTEGER;

   c   INTEGER;

BEGIN

   FOR i IN 4 .. 11

   LOOP

      SELECT COUNT (*)

        INTO c

        FROM mobilearea

       WHERE shortno LIKE SUBSTR (mobileno, 1, i) || '%';

      s := '000';

      IF c = 0

      THEN

         EXIT;

      ELSE

         IF c = 1

         THEN

            SELECT areacode

              INTO s

              FROM mobilearea

             WHERE shortno LIKE SUBSTR (mobileno, 1, i) || '%';

            EXIT;

         END IF;

      END IF;

   END LOOP;

   RETURN s;

END getmobilearea;

/

转载于:https://www.cnblogs.com/hibernate315/archive/2010/04/26/2399281.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值