EDUCBA

EDUCBA

MENUMENU
  • Blog
  • Free Courses
  • All Courses
  • All in One Bundle
  • Login
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.

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

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
GOLANG Course Bundle - 6 Courses in 1
23+ Hours of HD Videos
6 Courses
Verifiable Certificate of Completion
Lifetime Access
4.5
iOS DEVELOPER Course Bundle - 61 Courses in 1
147+ Hours of HD Videos
61 Courses
Verifiable Certificate of Completion
Lifetime Access
4.5
JAVA SERVLET Course Bundle - 18 Courses in 1 | 6 Mock Tests
56+ Hours of HD Videos
18 Courses
6 Mock Tests & Quizzes
Verifiable Certificate of Completion
Lifetime Access
4.5
RED HAT LINUX Course Bundle - 5 Courses in 1
28+ Hours of HD Videos
5 Courses
Verifiable Certificate of Completion
Lifetime Access
4.5
Primary Sidebar
Popular Course in this category
ORACLE DBA Database Management System Course Bundle - 2 Courses in 1
 20+ Hours of HD Videos
2 Courses
Verifiable Certificate of Completion
  Lifetime Access
4.5
Price

View Course
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Database Management
  • Machine Learning
  • All Tutorials
Certification Courses
  • All Courses
  • Data Science Course - All in One Bundle
  • Machine Learning Course
  • Hadoop Certification Training
  • Cloud Computing Training Course
  • R Programming Course
  • AWS Training Course
  • SAS Training Course

ISO 10004:2018 & ISO 9001:2015 Certified

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

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

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

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

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more