首页 > Linux操作系统 > Linux操作系统 > 连接条件字符类型不一样。
drop table wxh_tbd1;
Table dropped.
rop table wxh_tbd2;
Table dropped.
create table wxh_tbd1 (id number ,name varchar2(2000));
Table created.
create table wxh_tbd2 (id varchar2(1000) ,name varchar2(2000));
Table created.
insert into wxh_tbd1 select object_id,object_name from dba_objects;
18667 rows created.
commit;
Commit complete.
insert into wxh_tbd2 select object_id,object_name from dba_objects;
18667 rows created.
commit;
Commit complete.
create index t2 on wxh_tbd1(id);
Index created.
create index t3 on wxh_tbd2(id);
Index created.
create index t1 on wxh_tbd1(name);
Index created.
select * from wxh_tbd1 a ,wxh_tbd2 b where a.id=b.id and a.name='1';
no rows selected
Execution Plan
----------------------------------------------------------
Plan hash value: 422716281
-----------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-----------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 2519 | 26 (4)| 00:00:01 |
| 1 | NESTED LOOPS | | | | | |
| 2 | NESTED LOOPS | | 1 | 2519 | 26 (4)| 00:00:01 |
| 3 | TABLE ACCESS FULL | WXH_TBD2 | 19022 | 27M| 25 (0)| 00:00:01 |
|* 4 | INDEX RANGE SCAN | T1 | 1 | | 0 (0)| 00:00:01 |
|* 5 | TABLE ACCESS BY INDEX ROWID| WXH_TBD1 | 1 | 1015 | 0 (0)| 00:00:01 |
-----------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
4 - access("A"."NAME"='1')
5 - filter("A"."ID"=TO_NUMBER("B"."ID"))
select * from wxh_tbd1 a ,wxh_tbd2 b where to_char(a.id)=b.id and a.name='1';
no rows selected
Execution Plan
----------------------------------------------------------
Plan hash value: 186266070
------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 2519 | 3 (0)| 00:00:01 |
| 1 | NESTED LOOPS | | | | | |
| 2 | NESTED LOOPS | | 1 | 2519 | 3 (0)| 00:00:01 |
| 3 | TABLE ACCESS BY INDEX ROWID| WXH_TBD1 | 1 | 1015 | 1 (0)| 00:00:01 |
|* 4 | INDEX RANGE SCAN | T1 | 1 | | 1 (0)| 00:00:01 |
|* 5 | INDEX RANGE SCAN | T3 | 1 | | 1 (0)| 00:00:01 |
| 6 | TABLE ACCESS BY INDEX ROWID | WXH_TBD2 | 1 | 1504 | 2 (0)| 00:00:01 |
------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
4 - access("A"."NAME"='1')
5 - access("B"."ID"=TO_CHAR("A"."ID"))
ORACLE为什么不去对A表的id通过to_char转换,而总是会在varchar2的类型字段上增加to_number函数。
数字转char总是可以成功的,而char转number是可能报错的。而oracle总是倾向与后者。不知道为什么。
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/22034023/viewspace-683598/ ,如需转载,请注明出处,否则将追究法律责任。