Oracle数据库to_date()和to_char()的相关

to_date '08-30' 到 '08-30' 是没有数据的 必须加水 >=to_date('2016-08-30 00:00:00','yyyy-MM-dd hh24:mi:ss')
) 

select * from T_A a where a.begintime=to_date('2013-1-1','yyyy-mm-dd');


select * from T_A a where to_char(a.begintime,'yyyy-mm-dd')='2013-1-1';

查询结果是一样的.

区别在于 查询的 处理步骤不一样.

select * from T_A a where a.begintime=to_date('2013-1-1','yyyy-mm-dd');
是先把 '2013-1-1' 这个字符串, 转换为日期格式, 然后去和数据库里面做比较.
如果有 1000 行数据, 那么操作就是
1次 字符转换为 日期, 1000 次日期比较。

select * from T_A a where to_char(a.begintime,'yyyy-mm-dd')='2013-1-1';
是把数据库里面的每一行的 begintime, 转换为 字符格式, 然后去和数据库里面做比较。
如果有 1000 行数据, 那么操作就是
1000次 日期转换为字符, 1000 次字符串比较。
posted @ 2016-08-29 18:42  F领主  阅读(188)  评论(0编辑  收藏  举报