select * from a where to_char(rq, 'yyyymmdd') = '20030923'
SQL> select * from test where mydate=to_date('2003-4-12','yyyy-mm-dd');MYDATE ---------- 12-4月 -03 12-4月 -03SQL> select * from test where mydate=to_date('2003-04-12','yyyy-mm-dd');MYDATE ---------- 12-4月 -03 12-4月 -03SQL> select * from test where mydate='12-4月-2003';MYDATE ---------- 12-4月 -03 12-4月 -03SQL> select * from test where to_char(mydate,'yyyy-mm-dd')='2003-4-12';未选定行SQL> select * from test where to_char(mydate,'yyyymmdd')='20030412';MYDATE ---------- 12-4月 -03 12-4月 -03SQL> select * from test where to_char(mydate,'yyyy-mm-dd')='2003-04-12';MYDATE ---------- 12-4月 -03 12-4月 -03请你比较这几个的区别,用to_char要小心。
考虑“时间”和性能,最好的方式应该是例如查询“2003年3月12日”select * from test where mydate >= to_date('2003-03-12', 'YYYY-MM-DD') and mydate < to_date('2003-03-13', 'YYYY-MM-DD')
select * from test where mydate = to_date('2003-03-12', 'yyyy-mm-dd')的效率绝对比 select * from test where to_char(mydate, 'yyyy-mm-dd') = '2003-03-12'要高!!至于select * from test where mydate = to_date('2003-03-12', 'yyyy-mm-dd')和楼上的 select * from test where mydate >= to_date('2003-03-12', 'YYYY-MM-DD') and mydate < to_date('2003-03-13', 'YYYY-MM-DD') 孰优孰劣,由于没有经过测试比较,不好说。
----------
12-4月 -03
12-4月 -03SQL> select * from test where mydate=to_date('2003-04-12','yyyy-mm-dd');MYDATE
----------
12-4月 -03
12-4月 -03SQL> select * from test where mydate='12-4月-2003';MYDATE
----------
12-4月 -03
12-4月 -03SQL> select * from test where to_char(mydate,'yyyy-mm-dd')='2003-4-12';未选定行SQL> select * from test where to_char(mydate,'yyyymmdd')='20030412';MYDATE
----------
12-4月 -03
12-4月 -03SQL> select * from test where to_char(mydate,'yyyy-mm-dd')='2003-04-12';MYDATE
----------
12-4月 -03
12-4月 -03请你比较这几个的区别,用to_char要小心。
名称 空? 类型
------------------------- -------- ------- MYDATE DATE
SQL> select * from test;MYDATE
----------
12-3月 -03
12-4月 -03
12-5月 -03
12-4月 -03
where mydate >= to_date('2003-03-12', 'YYYY-MM-DD')
and mydate < to_date('2003-03-13', 'YYYY-MM-DD')
select * from test where to_char(mydate, 'yyyy-mm-dd') = '2003-03-12'要高!!至于select * from test where mydate = to_date('2003-03-12', 'yyyy-mm-dd')和楼上的
select * from test
where mydate >= to_date('2003-03-12', 'YYYY-MM-DD')
and mydate < to_date('2003-03-13', 'YYYY-MM-DD')
孰优孰劣,由于没有经过测试比较,不好说。