当前位置: 代码迷 >> Oracle开发 >> 求教oracle时间有关问题!
  详细解决方案

求教oracle时间有关问题!

热度:215   发布时间:2016-04-24 06:23:30.0
求教oracle时间问题!!!
我有一个字段是varchar2类型的。存的是时间格式20150917140932。我想转换成2015-09-17在where条件中检索出来为什么不行呢?检索没数据
select id,to_char(to_date(date_validated, 'yyyy-MM-dd hh24:mi:ss'),'yyyy-mm-dd'),type, ids, parameters
 from tttt
 where to_char(to_date(date_validated, 'yyyy-MM-dd hh24:mi:ss'),'yyyy-mm-dd')> '2015-09-17'
------解决思路----------------------

select id,to_char(to_date(date_validated, 'yyyy-MM-dd hh24:mi:ss'),'yyyy-MM-dd'),type, ids, parameters
 from tttt
 where to_date(date_validated, 'yyyy-MM-dd hh24:mi:ss')>to_date( '2015-09-17','yyyy-MM-dd')

试试
------解决思路----------------------
试试这样可不可以

select id,to_char(to_date(date_validated, 'yyyy-MM-dd hh24:mi:ss'),'yyyy-mm-dd'),type, ids, parameters
 from tttt
 WHERE to_date(date_validated, 'yyyy-MM-dd hh24:mi:ss')> to_date('2015-09-17','yyyy-mm-dd hh24:mi:ss')

------解决思路----------------------
select to_char(to_date('20150917140932', 'yyyy-MM-dd hh24:mi:ss'),'yyyy-mm-dd') from dual
返回的结果就是2015-09-17
如果where中是>,应该没结果的,要>=吧。
------解决思路----------------------
to_char(to_date(date_validated, 'yyyy-MM-dd hh24:mi:ss'),'yyyy-mm-dd')> '2015-09-17'
如果date_validated为20150917140932的话,两边就相等了
  相关解决方案