I'm using Oracle DB (Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production) and my table definition is like this:
Create table CardInfo (
Id Number not null,
BalanceInfo Decimal,
...
...
);
A lot of times this table will be queried like this:
select Id, ... from CardInfo where BalanceInfo > 0;
So, I'm trying to create a function based index like this:
CREATE INDEX balance_ix ON CardInfo (BalanceInfo > 0);
However, above statement gives following error:
Error starting at line : 1 in command -
CREATE INDEX balance_ix ON CardInfo (BalanceInfo > 0);
Error report -
ORA-00907: missing right parenthesis
00907. 00000 - "missing right parenthesis"
Cause:
Action:
So I changed my create index statement to following:
CREATE INDEX balance_ix ON CardInfo (BalanceInfo);
This executed fine and created the index. However, when I did a Explain Plan for my sql statement like this:
EXPLAIN PLAN
SET statement_id = 'ex_plan1' FOR
SELECT * FROM CardInfo WHERE BalanceInfo > 0;;
SELECT PLAN_TABLE_OUTPUT
FROM TABLE(DBMS_XPLAN.DISPLAY(NULL, 'ex_plan1','BASIC'));
It produced the following output:
Plan hash value: 97071123
-------------------------------------------
| Id | Operation | Name |
-------------------------------------------
| 0 | SELECT STATEMENT | |
| 1 | TABLE ACCESS FULL| CardInfo |
-------------------------------------------
This means that it is not using the index that I created.
Could someone help, how can i create an index so that my sql statement uses it ? Thanks in advance.