oracle case 唯一索性,case 函数索引有限制??

本文展示了如何在Oracle SQL中创建表、函数以及基于函数的索引。在创建过程中遇到了函数不能确定已用时间的问题,通过设置函数为DETERMINISTIC解决了问题。之后成功创建了索引,并进行了查询操作,查询计划显示使用了动态采样。
摘要由CSDN通过智能技术生成

但是可以骗oracle

SQL> create table tcase(d date,n number);

表已创建。

已用时间:  00: 00: 00.23

SQL> create function fcase return date is begin return sysdate; end;

2  /

函数已创建。

已用时间:  00: 00: 00.32

SQL> create index ti on tcase(case d when fcase then 1 else 2 end);

create index ti on tcase(case d when fcase then 1 else 2 end)

*

第 1 行出现错误:

ORA-30553: 函数不能确定

已用时间:  00: 00: 00.04

SQL> create function fcase2 return date DETERMINISTIC is begin return sysdate; end;

2  /

函数已创建。

已用时间:  00: 00: 00.01

SQL> create index ti on tcase(case d when fcase2 then 1 else 2 end);

索引已创建。

已用时间:  00: 00: 00.14

SQL> select * from tcase where (case d when fcase2 then 1 else 2 end)=1;

未选定行

已用时间:  00: 00: 00.03

SQL> set autot on

SQL> /

未选定行

已用时间:  00: 00: 00.00

执行计划

----------------------------------------------------------

Plan hash value: 3675649526

-------------------------------------------------------------------------------------

| Id  | Operation                   | Name  | Rows  | Bytes | Cost (%CPU)| Time     |

-------------------------------------------------------------------------------------

|   0 | SELECT STATEMENT            |       |     1 |    25 |     1   (0)| 00:00:01 |

|   1 |  TABLE ACCESS BY INDEX ROWID| TCASE |     1 |    25 |     1   (0)| 00:00:01 |

|*  2 |   INDEX RANGE SCAN          | TI    |     1 |       |     1   (0)| 00:00:01 |

-------------------------------------------------------------------------------------

Predicate Information (identified by operation id):

---------------------------------------------------

2 - access(CASE "D" WHEN "HR"."FCASE2"() THEN 1 ELSE 2 END =1)

Note

-----

- dynamic sampling used for this statement (level=2)

统计信息

----------------------------------------------------------

0  recursive calls

0  db block gets

1  consistent gets

0  physical reads

0  redo size

344  bytes sent via SQL*Net to client

408  bytes received via SQL*Net from client

1  SQL*Net roundtrips to/from client

0  sorts (memory)

0  sorts (disk)

0  rows processed

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值