|
-
I found similiar question:
http://asktom.oracle.com/pls/ask/f?p...g4636346663651
Tom said:
=== BEGIN OF WHAT TOM SAID ========
If you have my book -- I answer your #3 question in "why isn't my index getting
used" in the chapter on indexes. column XXX is a varchar2 column. You are
comparing a string to a number. So
select * from t where xxx = 123
is REALLY
select * from t where to_number(xxx) = 123;
you are applying a function to the column XXX implicitly. That invalidates the
index usage. When you code:
select * from t where xxx = '123'
you are comparing a string to a string and lo and behold -- no such conversion
takes place.
ALWAYS COMPARE STRINGS TO STRINGS, DATES TO DATES, NUMBERS TO NUMBERS. do not
rely on implicit conversion -- ever!
=== END OF WHAT TOM SAID ========
How about my where clause:
A_NUMBER_COL = 'A_STRING_WHICH_CONTAIN_ONLY_DIGITS'
???
Is the above query is:
select ... from test where TO_CHAR(A_NUMBER_COL )='12345';
or
select ... from test where A_NUMBER_COL=TO_NUMBER('12345');
According my test of whether an index is used, it seems
to me that Oracle converts to:
select ... from test where A_NUMBER_COL=TO_NUMBER('12345');
Thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|