I have a query as:
select * from tab1
This query doesn't make use of an index. Can you tell me a better way to write this query so that it makes use of an index? It would help me greatly. Thanks in advance.
You didn't say which version of Oracle you are running. It can make a difference to the answer.
This problem plagued many SQL queries for many people. So you are not alone. The problem is that your TRUNC function invalidates the use of any index on the CHECK_DATE column. Starting with Oracle 8i, the concept of a Function Based Index was introduced. This lets one create an index on a column at the same time, using a function on that column. The Function Based Index is created as follows:
CREATE INDEX check_date_trunc_idx ON table_name TRUNC(check_date);
In the index, the TRUNC function is now applied to column so that queries such as yours can use this index. There is much more to Function Based Indexes, and I suggest that you read the Oracle 8i Concepts guide for more information.
For More Information
- What do you think about this answer? E-mail us at editor@searchDatabase.com with your feedback.
- The Best Oracle Web Links: tips, tutorials, scripts, and more.
- Have an Oracle tip to offer your fellow DBA's and developers? The best tips submitted will receive a cool prize--submit your tip today!
- Ask your technical Oracle questions--or help out your peers by answering them--in our live discussion forums.
- Ask the Experts yourself: Our Oracle gurus are waiting to answer your toughest questions.
Dig Deeper on Oracle database design and architecture
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.