
/*
 * 当出现隐式转换时，查询不会走索引，会走全表扫描
 */
prompt
prompt 'create table eoda.t'
declare row_count number(5);
begin
	select count(1) into row_count from user_tables where table_name = upper('t');
	if row_count = 1 then
		execute immediate 'drop table eoda.t';
	end if;
	execute immediate '
		create table eoda.t (x char(1) constraint t_pk primary key, y date)
	';
end;
/

prompt
prompt 'insert data into eoda.t'
begin
	insert into eoda.t values ('5',sysdate);
	commit;
end;
/

-- 存在隐式转换 to_number(x) = 5
explain plan for select * from eoda.t where x = 5
select * from table(dbms_xplan.display);
-- 强制使用唯一索引，还是存在隐式转换 to_number(x) = 5;
explain plan for select /*+ INDEX(t t_pk) */ * from eoda.t where x = 5;
select * from table(dbms_xplan.display);
-- 不存在隐式转换，直接使用唯一索引
explain plan for select * from eoda.t where x = '5';
select * from table(dbms_xplan.dislay);

