Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Oracle does Table scan for numbers

714811Jan 13 2010 — edited Jan 13 2010
When I use a numeric value against a column defined as varchar in the where caluse, Oracle is performing a full table scan though an index exist for that column. Is there any reason why Oracle behaves this way? I am using 10.2.0.3.0

create table employees (empid varchar2(3));

insert into employees values ('123');

create index emp_index on employees (empid);

select * from employees where empid = '123'; --- Index range scan

select * from employees where empid = 123; ---- Full Table scan

select * from employees where empid = to_char(123); ---- Index range scan

However, this is not the case when I use a string in where clause against a column defined as number.

create table managers (mgr_id number(3));

insert into managers values (123);

create index mgr_index on managers (mgr_id);

select * from managers where mgr_id = 123; --- Index range scan

select * from managers where mgr_id = '123'; -- Index range scan
This post has been answered by Centinul on Jan 13 2010
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 10 2010
Added on Jan 13 2010
2 comments
722 views