EDUCBA Logo

EDUCBA

MENUMENU
  • Explore
    • EDUCBA Pro
    • PRO Bundles
    • Featured Skills
    • New & Trending
    • Fresh Entries
    • Finance
    • Data Science
    • Programming and Dev
    • Excel
    • Marketing
    • HR
    • PDP
    • VFX and Design
    • Project Management
    • Exam Prep
    • All Courses
  • Blog
  • Enterprise
  • Free Courses
  • Log in
  • Sign Up
Home Data Science Data Science Tutorials Oracle Tutorial Oracle Function-based Index
 

Oracle Function-based Index

Priya Pedamkar
Article byPriya Pedamkar

Updated May 29, 2023

Oracle Function-based Index

 

 

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 enable queries to evaluate the value returned by a word. It provides direct and fast access to rows.

Watch our Demo Courses and Videos

Valuation, Hadoop, Excel, Mobile Apps, Web Development & many more.

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 a User-defined function.

Specification of an Index

An index is a schema object. Indexes are independent of the table they Indexes, both logically and physically. When someone drops a table, they also drop the corresponding indexes automatically. Although it is possible to create more than one index on a table, it does not necessarily mean that having more indexes results in faster performance. Each DML operation committed on a table with an index requires updating the index. Index reduces the disk I/O by using a rapid path access method to locate the data quickly.

Points of Concentration

  • The OWN schema must contain the table or cluster that needs to be indexed.
  • Create Index system privilege must be available for users who 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.
  • Function-Based Indexes defined with the UPPER (ColumnName) OR LOWER (ColumnName) allow case-sensitive searches.
  • Users should have to to Execute object privilege on the functions used in the Function-based indexes.
  • 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.

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:

sample table

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:

Without FUNCTION Based Index

Explanation: The above execution plan of the above SELECT statement scanned the full Employee table. The Employee table does not have an index, so the data is being retrieved using an Oracle function-based expression in the SELECT statement above.

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:

Oracle Function-based Index3

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:

fetch the rows

Explanation: The above execution plan of the above SELECT statement shows that the table accessed by Index ROWID is 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.

Code:

SELECT Table_Name,Index_Name FROM USER_INDEXES WHERE TABLE_NAME='EMPLOYEE';

Output:

Oracle Function-based Index5

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:

Oracle Function-based Index6

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:

Oracle Function-based Index7

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 a 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, the appropriate syntax when to create it along with sample code. You can also go through our other related articles to learn more –

  1. Oracle Date Functions
  2. Oracle Window Functions
  3. Function in Oracle
  4. Oracle String Functions

Primary Sidebar

Footer

Follow us!
  • EDUCBA FacebookEDUCBA TwitterEDUCBA LinkedINEDUCBA Instagram
  • EDUCBA YoutubeEDUCBA CourseraEDUCBA Udemy
APPS
EDUCBA Android AppEDUCBA iOS App
Blog
  • Blog
  • Free Tutorials
  • About us
  • Contact us
  • Log in
Courses
  • Enterprise Solutions
  • Free Courses
  • Explore Programs
  • All Courses
  • All in One Bundles
  • Sign up
Email
  • [email protected]

ISO 10004:2018 & ISO 9001:2015 Certified

© 2025 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

EDUCBA Login

Forgot Password?

🚀 Limited Time Offer! - 🎁 ENROLL NOW