日期:2014-05-17  浏览次数:20733 次

orecle在线急问```````


to_date(b.installationdate,'yyyy-mm-dd') between '2000-4-28' and '2006-4-28'

请问我这里写错了吗`???
我只想取字段中``某时间到某时间

installationdate
2008-06-01
2008-05-01
2008-06-01


------解决方案--------------------
between和and中是字符串类型的, 前面是date类型的, 不能作比较, 需要先to_date

SQL code
SQL> select HIREDATE from emp e where e.hiredate
  2  between to_date('1980-1-1','yyyy-mm-dd') and to_date('1981-1-1','yyyy-mm-dd')
  3  /
 
HIREDATE
-----------
1980-12-17

------解决方案--------------------
SQL code

SQL> select * from t3
  2  where to_date(installationdate,'yyyy-mm-dd') between '2008-05-01' and '2008-05-08';

select * from t3
where to_date(installationdate,'yyyy-mm-dd') between '2008-05-01' and '2008-05-08'

ORA-01861: literal does not match format string

SQL> 
SQL> select * from t3
  2  where to_date(installationdate,'yyyy-mm-dd')
  3  between to_date('2008-05-01','yyyy-mm-dd') and to_date('2008-05-08','yyyy-mm-dd');

INSTALLATIONDATE
------------------------------
2008-05-01

SQL> select * from t3;

INSTALLATIONDATE
------------------------------
2008-06-01
2008-05-01
2008-06-01

------解决方案--------------------
本身DATA类型的不能用to_date
date型的必须和date型的比较,不能和字符型的比较
ORACLE里对DATE型和VARCHAR的比较比SQL SERVER里严格
------解决方案--------------------
引用楼主 w2571121444 的帖子:


to_date(b.installationdate,'yyyy-mm-dd') between '2000-4-28' and '2006-4-28'

请问我这里写错了吗`???
我只想取字段中``某时间到某时间

installationdate
2008-06-01
2008-05-01
2008-06-01