Using Functions in WHERE Clause May Cause Indexes To Be Suppressed
Unless you are using function-based indexes, using functions on indexed columns in the WHERE clause of a SQL statement will cause the database optimizer to bypass indexes. Some of the most common functions in Oracle are TRUNC, SUBSTR, TO_DATE, TO_CHAR, and INSTR. All of these functions will cause the value of the column to be altered. Therefore, the indexes and the columns being referenced will not be used.
The following statement would cause a full table scan to be performed, even if there is an index on the hire_date column (as long as it wasn’t a function-based index):
select empno, ename, deptno
from emp
where trunc(hiredate) = '01-MAY-01';
Changing the statement to the following would allow for an index lookup:
select empno, ename, deptno
from emp
where hiredate > '01-MAY-01'
and hiredate < (TO_DATE('01-MAY-01') + 0.99999);
By altering the values being compared to the column, and not the columns themselves, the indexes become available. This is used to eliminate full table scans.