国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > 綜合 > 正文

基于自定義函數(shù)的Function-Based索引創(chuàng)建

2024-07-21 02:32:48
字體:
供稿:網(wǎng)友
留言版上的第2330號(hào)問題是:
在oralce中給自建函數(shù)創(chuàng)建索引,結(jié)果不成功。source:Create Index IDX_T_SP_TWOTYPESTAT_0_f On T_SP_TWOTYPESTAT_0(f_dateadd(yearmonth,12,2));
err:the function is not deterministic.
我們看一下這是為什么?隨便一個(gè)測(cè)試可以再現(xiàn)這個(gè)問題,我門創(chuàng)建一個(gè)函數(shù)(本范例函數(shù)用于進(jìn)行16進(jìn)制向10進(jìn)制轉(zhuǎn)換):CREATE OR REPLACE FUNCTION h2ten (
   p_str         IN   VARCHAR2,
   p_from_base   IN   NUMBER DEFAULT 16
)
   RETURN NUMBER
IS
   l_num   NUMBER        DEFAULT 0;
   l_hex   VARCHAR2 (16) DEFAULT '0123456789ABCDEF';
BEGIN
   FOR i IN 1 .. LENGTH (p_str)
   LOOP
      l_num :=
         l_num * p_from_base + INSTR (l_hex, UPPER (SUBSTR (p_str, i, 1)))
         - 1;
   END LOOP;   RETURN l_num;
END h2ten;
 此時(shí)創(chuàng)建索引,獲得如下錯(cuò)誤信息:SQL> create table t as select username,'a' hex from dba_users;Table createdSQL> create index i_t on t (h2ten(hex));create index i_t on t (h2ten(hex))ORA-30553: The function is not deterministic
 假如需要?jiǎng)?chuàng)建基于自定義函數(shù)的索引,那么我們需要指定deterministic參數(shù):CREATE OR REPLACE FUNCTION h2ten (
   p_str         IN   VARCHAR2,
   p_from_base   IN   NUMBER DEFAULT 16
)
   RETURN NUMBER DETERMINISTIC
IS
   l_num   NUMBER        DEFAULT 0;
   l_hex   VARCHAR2 (16) DEFAULT '0123456789ABCDEF';
BEGIN
   FOR i IN 1 .. LENGTH (p_str)
   LOOP
      l_num :=
         l_num * p_from_base + INSTR (l_hex, UPPER (SUBSTR (p_str, i, 1)))
         - 1;
   END LOOP;   RETURN l_num;
END h2ten;此時(shí)創(chuàng)建索引即可: SQL> create index i_t on t (h2ten(hex));Index created Oracle這樣解釋這個(gè)參數(shù):
The hint DETERMINISTIC helps the optimizer avoid redundant function calls. If a stored function was called PReviously with the same arguments, the optimizer can elect to use the previous result. The function result should not depend on the state of session variables or schema objects. Otherwise,
results might vary across calls. Only DETERMINISTIC functions can be called from a function-based index or a materialized view that has query-rewrite enabled.


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 来宾市| 湘西| 六安市| 云梦县| 威海市| 桃江县| 襄垣县| 永顺县| 祁连县| 沅陵县| 兰坪| 仙游县| 鲁山县| 敦煌市| 南汇区| 三明市| 湛江市| 荥阳市| 酒泉市| 丰顺县| 靖西县| 沈丘县| 阿尔山市| 阿荣旗| 仁寿县| 霞浦县| 清水河县| 独山县| 嘉善县| 团风县| 西乌珠穆沁旗| 怀来县| 浦城县| 淳化县| 赣榆县| 丹阳市| 永登县| 马关县| 云梦县| 棋牌| 日照市|