EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 360+ Courses All in One Bundle
  • Login

Oracle Function-based Index

By Priya PedamkarPriya Pedamkar

Home » Data Science » Data Science Tutorials » Oracle Tutorial » Oracle Function-based Index

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 enables query to evaluate value returned by an expression. It provides direct and fast access to rows.

Syntax

Creating an Index:

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

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:

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. 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:

Oracle Function-based Index3

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:

fetch the rows

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.

Popular Course in this category
Sale
Oracle Training (14 Courses, 8+ Projects)14 Online Courses | 8 Hands-on Projects | 120+ Hours | Verifiable Certificate of Completion | Lifetime Access
4.5 (8,949 ratings)
Course Price

View Course

Related Courses
Oracle DBA Database Management System Training (2 Courses)All in One Financial Analyst Bundle - 250+ Courses, 40+ Projects

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

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:

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 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 –

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

Oracle Training (14 Courses, 8+ Projects)

14 Online Courses

8 Hands-on Projects

120+ Hours

Verifiable Certificate of Completion

Lifetime Access

Learn More

0 Shares
Share
Tweet
Share
Primary Sidebar
Oracle Tutorial
  • Advanced
    • Timestamp to Date in Oracle
    • Oracle Describe Table
    • Oracle Clauses
    • Oracle Having Clause
    • Oracle FOREIGN Key
    • PIVOT in Oracle
    • Oracle Alter Table
    • Oracle Queries
    • Oracle Views
    • Oracle Window Functions
    • Oracle String Functions
    • Oracle Date Functions
    • Oracle Analytic Functions
    • Oracle Aggregate Functions
    • Select in Oracle
    • INSERT in Oracle
    • DISTINCT in Oracle
    • Function in Oracle
    • Oracle GROUP_CONCAT
    • Oracle INSTR()
    • Oracle CONVERT
    • Oracle LENGTH()
    • Oracle EXISTS
    • Oracle REPLACE()
    • Oracle MERGE
    • Oracle LEAD()
    • Oracle EXTRACT()
    • Oracle LISTAGG()
    • Oracle SYS_CONTEXT()
    • Oracle COALESCE
    • Oracle NVL()
    • Oracle SYSDATE()
    • Oracle?Date Format
    • Oracle SYS_GUID()
    • Oracle WILDCARDS
    • Oracle Synonyms
    • Oracle Subquery
    • BETWEEN in Oracle
    • FETCH in Oracle
    • Oracle Index
    • Oracle Function-based Index
    • Oracle UNIQUE Index
    • Oracle Bitmap Index
    • Oracle Column
    • Oracle Triggers
    • Oracle Procedures
    • Sample Database for Oracle
    • Oracle LIKE Operator
    • ORDER BY in Oracle
    • Oracle ORDER BY DESC
    • GROUP BY in Oracle
    • Oracle GROUP BY HAVING
    • Oracle Aliases
    • Table in Oracle
    • Oracle Temporary Table
    • Oracle? Table Partition
    • Oracle rename table
    • Oracle CTE
    • Cursor in Oracle
    • Oracle LOCK TABLE
    • Oracle Tablespace
    • Oracle CARDINALITY
    • Oracle REGEXP
    • Oracle REGEXP_REPLACE
    • Oracle to_date
    • JSON in Oracle
    • Oracle COMMIT
    • Oracle GRANT
    • Oracle MD5
    • Oracle ROLLBACK
    • Oracle Users
    • Oracle TIMESTAMP
    • IF THEN ELSE in Oracle
    • Oracle While Loop
    • Oracle Clone Database
    • Oracle Backup Database
    • Oracle? XML
    • Oracle XMLAGG
    • Oracle XMLTABLE
    • Oracle Performance Tuning
    • Oracle B Tree Index
    • Oracle fusion
    • Oracle ebs
    • Oracle GRC
    • Oracle Cloud
    • Oracle HCM Cloud
    • Oracle Integration Cloud
    • Oracle Jinitiator
    • Oracle pathfinder
    • Oracle VirtualBox
    • Oracle Weblogic Server
    • Oracle decode
    • Oracle Exadata
    • Oracle ZFS
    • Oracle? utilities
    • JDBC Driver for Oracle
    • Oracle? DBA Versions
    • Oracle DBA Salary
  • Basic
    • Oracle Marketing Cloud
    • What is Oracle?
    • Career in Oracle
    • How to Install Oracle
    • Oracle Versions
    • What Is Oracle Database
    • Oracle Data Warehousing
    • Oracle Warehouse Builder
    • Career In Oracle Database Administrator
    • Career In Oracle DBA
    • What is Oracle RAC
    • Oracle DBA
    • Oracle? Vanderbilt
    • What is RMAN Oracle
    • Oracle Database Administration
    • Oracle Operators
    • Oracle Constraints
    • Oracle number
    • Oracle Data Types
    • Oracle UNIQUE Constraint
    • Oracle Check Constraint
  • Joins
    • Joins in Oracle
    • Inner Join in Oracle
    • Oracle Cross Join
    • Left Join in Oracle
    • OUTER Join in Oracle
    • Oracle Full Outer Join
    • Natural Join in Oracle
    • Oracle Self Join
    • Oracle hash join
    • Oracle? Update with Join
  • Oracle SET Operators
    • UNION in Oracle
    • Oracle UNION ALL
    • INTERSECT in Oracle
    • MINUS in Oracle
  • Interview Questions
    • Oracle Interview Questions
    • Oracle Apps Interview Questions
    • Oracle Apps Technical Interview Questions
    • Oracle Database Interview Questions
    • Oracle Forms Interview Questions
    • Oracle PL/SQL Interview Questions
    • Oracle RAC Interview Questions
    • Oracle SOA Interview Questions

Related Courses

Oracle Course Training

Oracle DBA Certification Course

MongoDB Certification Training

Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • 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

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

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

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

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

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

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

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

Let’s Get Started

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

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

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

EDUCBA

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

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

Special Offer - Oracle Training (14 Courses, 8+ Projects) Learn More