to_date掩码的小问题
六月 22, 2009 – 11:39 上午最近同事在写SQL的犯了个小错误,让原来十几秒的SQL跑了二十多分钟。
错误是出现在to_date的日期掩码上的,如下:
SQL> select to_date(’20090101′,’yyyy-mm-dd’) from dual;
TO_DATE(’20090101′,
——————-
2009-01-01 00:00:00
日期格式和日期的掩码格式并不一致,但是ORACLE没有报错,结果也是对的。
但是虽然结果是正确的,但这样的转换对分区裁剪是有影响的。
这个时候对于分区表是不能进行分区裁减的,只能走全表扫描。
SQL> create table sunwg01
2 (id number,
3 birth date)
4 partition by range(birth)
5 (partition p1 values less than(to_date(’20090101′,’yyyymmdd’)),
6 partition p2 values less than(to_date(’20090102′,’yyyymmdd’)),
7 partition p3 values less than(to_date(’20090103′,’yyyymmdd’)));
Table created.
SQL> set autot traceonly exp
SQL> select * From sunwg01 where birth=to_date(’20090101′,’yyyy-mm-dd’);
Execution Plan
———————————————————-
Plan hash value: 164324935
——————————————————————
| Id | Operation | Name | Rows | Pstart| Pstop |
——————————————————————
| 0 | SELECT STATEMENT | | 1 | | |
| 1 | PARTITION RANGE SINGLE| | 1 | KEY | KEY |
|* 2 | TABLE ACCESS FULL | SUNWG01 | 1 | KEY | KEY |
——————————————————————
Predicate Information (identified by operation id):
—————————————————
2 - filter(”BIRTH”=TO_DATE(’20090101′,’yyyy-mm-dd’))
Note
—–
- dynamic sampling used for this statement