Introduction to Oracle Function-based Index
Oracle Function-based Index is a schema object which contains an entry for each value that appears in the indexed column(s) of the Table or Cluster. Function-based indexes are based on expressions and enables query to evaluate value returned by an expression. It provides direct and fast access to rows.
Syntax
Creating an Index:
CREATE INDEX IndexName ON Table (Function);
Dropping an Index:
DROP INDEX IndexName;
Explanation:
IndexName: It can be any name of that Index object according to the Oracle naming convention.
Function: It can be an Oracle function or User-defined function.
Specification of an Index
An index is a schema object. The index is used by the Oracle server to speed up retrieval of rows by using a pointer. Indexes are independent of the table it Indexes, both logically and physically. The index is used and maintained automatically by the Oracle server. Indexes can be created or dropped at any time and have no effect on the base tables or other indexes.
When a table is dropped, the corresponding indexes are also dropped automatically. On one table more than one Index can be created, but this does not mean that more indexes lead to faster performance. Each DML operation that is committed on a table with Index means that the Index must be updated. Index reduces the disk I/O by using a rapid path access method to locate the data quickly.
Points of Concentration
- The Table or Cluster to be indexed must be in the OWN schema.
- Index object privilege should be available on the table to be indexed.
- Create Index system privilege must be available for the user who needs to create index and query rewrite privileges.
- Unlimited tablespace system privilege or space quota on space quota on tablespaces must be available.
- Function-based indexes based on expressions in SELECT statements.
- The index expressions are built from table columns, containing SQL functions or user-defined functions.
- Function-Based Indexes defined with the UPPER (ColumnName) OR LOWER (ColumnName) allow case sensitive searches.
- Users should have Execute object privilege on the functions used in the Function-based indexes.
- Function-Based indexes are designed to improve query performance when the function is used in the WHERE clause.
- To ensure that Oracle uses the Index rather than performing a full table scan, users should be sure that the value of the Function is NOT NULL in the subsequent queries.
- Oracle treats Indexes with columns marked DESC as Function-Based Indexes.
- The Function-Based Indexes are used only when the query statement is executed through the specified function.
Examples to Implement Oracle Function-based Index
Implementations of FUNCTION Based Index with Examples:
In this section, we’ll see the implementation of the Oracle Function-based Index and its behavior. For that, we will use the below sample table (Employee) with 14 records to understand the Oracle Function-based Index behavior.
Code:
SELECT * FROM Employee;
Output:
Example #1: Without FUNCTION Based Index
Code:
SELECT Name, Deptnumber, Salary, Bonus, Salary + NVL (Bonus, 0) Total FROM Employee where Salary + NVL(Bonus, 0) > 20000;
Output:
Explanation: The above execution plan of the above SELECT statement scanned the full Employee table. In the above SELECT statement, Oracle function-based expression being used to fetch the data from the Employee table but the table does not have an Index for that.
Example #2: FUNCTION Based Index
Now we’ll create a Function-Based Index for the above expression to prevent the full scan of the table and reduce the I/O cycle.
Code:
CREATE INDEX Emptotal ON Employee (Salary + NVL (Bonus, 0));
Output:
Now the Function Based Index has been created on the Employee table for the above expression. Now we’ll execute the above query to fetch the rows.
Code:
SELECT Name, Deptnumber, Salary, Bonus, Salary + NVL (Bonus, 0) Total FROM Employee where Salary + NVL (Bonus, 0) > 20000;
Output:
Explanation: The above execution plan of the above SELECT statement shows that the table accessed by Index ROWID not the full Employee table. And Execution plan clearly shows the difference in Cost.
Example #3: How to check Indexes
The index can be checked from the USER_INDEXES data dictionary.

4.5 (8,949 ratings)
View Course
Code:
SELECT Table_Name,Index_Name FROM USER_INDEXES WHERE TABLE_NAME='EMPLOYEE';
Output:
Example #4: Dropping Function-Based Index
The index can be dropped at any time but User needs to have drop privilege.
Code:
DROP INDEX Emptotal;
Output:
In the above example, using a drop index syntax index gets dropped. So now the Employee table does not have an “Emptotal” Index.
Code:
SELECT Table_Name,Index_Name FROM USER_INDEXES WHERE TABLE_NAME='EMPLOYEE';
Output:
When to Create Function-Based Index
The Function-Based expression is used frequently in the WHERE clause or in a join condition. The table is large and most queries are expected to retrieve less than 2 to 4 % of the rows.
TIP:
1. Should not create a Function-Based Index when the table is too small.
2. Should not create a Function-Based Index when the table is updated frequently.
Conclusion
Oracle Function Based Index reduces computation for the database. If any query consists of function-based expression and executes on a regular basis or multiple times then the database has to compute in everyone runs. To avoid this computation on the database every time the Function-Based Index is a better option.
Recommended Articles
This is a guide to Oracle Function-based Index. Here we discuss an introduction to Oracle Function-based Index, appropriate syntax, when to create along with sample code. You can also go through our other related articles to learn more –