0% found this document useful (0 votes)
16 views

Oracle

An index allows for faster retrieval of records from a database table by creating an entry for each value that appears in indexed columns. There are three main types of indexes: B-tree indexes, which Oracle uses by default; function-based indexes on columns or functions like UPPER(supplier_name); and unique indexes where combinations of column values must be unique. Indexes are created, renamed, and dropped using SQL commands like CREATE INDEX, ALTER INDEX, and DROP INDEX.

Uploaded by

Payal Jain
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Oracle

An index allows for faster retrieval of records from a database table by creating an entry for each value that appears in indexed columns. There are three main types of indexes: B-tree indexes, which Oracle uses by default; function-based indexes on columns or functions like UPPER(supplier_name); and unique indexes where combinations of column values must be unique. Indexes are created, renamed, and dropped using SQL commands like CREATE INDEX, ALTER INDEX, and DROP INDEX.

Uploaded by

Payal Jain
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

Oracle/PLSQL: Indexes

What is an Index?
An index is a performance-tuning method of allowing faster retrieval of records. n
indAex creates an entry for each value that appears in the indexed columns. By default,
Oracle creates B-tree indexes.

Create an Index
The syntax for creating a index is:
CREATE [UNIQUE] INDEX index_name
ON table_name (column1, column2, . column_n)

UNIQUE indicates that the combination of values in the indexed columns must be
unique.

For example:
CREATE INDEX supplier_idx
ON supplier (supplier_name);
In this example, we've created an index on the supplier table called supplier_idx. It
consists of only one field - the supplier_name field.

We could also create an index with more than one field as in the example below:
CREATE INDEX supplier_idx
ON supplier (supplier_name, city);

Create a Function-Based Index


In Oracle, you are not restricted to creating indexes on only columns. You can create
function-based indexes.
The syntax for creating a function-based index is:
CREATE [UNIQUE] INDEX index_name
ON table_name (function1, function2, . function_n)

For example:
CREATE INDEX supplier_idx
ON supplier (UPPER(supplier_name));
In this example, we've created an index based on the uppercase evaluation of the
supplier_name field.
However, to be sure that the Oracle optimizer uses this index when executing your SQL
statements, be sure that UPPER(supplier_name) does not evaluate to a NULL value. To
ensure this, add UPPER(supplier_name) IS NOT NULL to your WHERE clause as
follows:

SELECT supplier_id, supplier_name, UPPER(supplier_name)


FROM supplier
WHERE UPPER(supplier_name) IS NOT NULL
ORDER BY UPPER(supplier_name);

Rename an Index
The syntax for renaming an index is:
ALTER INDEX index_name
RENAME TO new_index_name;

For example:
ALTER INDEX supplier_idx
RENAME TO supplier_index_name;
In this example, we're renaming the index called supplier_idx to supplier_index_name.

Drop an Index
The syntax for dropping an index is:
DROP INDEX index_name;

For example:
DROP INDEX supplier_idx;
In this example, we're dropping an index called supplier_idx.

You might also like