现Oracle数据库中有一个表T,表中的字段有T_name,T_sex,T_date
其中T_date的数据类型为varchar2,录入的时间格式多样:
2018-08-01 00:00:00
2018-8-1 9:00:00
2018-8-01 9:00:00
2018-08-1 9:00:00
2018/8/1
2018/08/01 00:00:00
2018/8/1 9:00:00
2018/8/1
2018-10-24 星期日 下午 9:00:00
2018-10-24 星期日 下午 23:00:00
且较多的为:2018-08-01 00:00:00
2018-8-1 9:00:00
2018-8-01 9:00:00
2018-08-1 9:00:00
2018/8/1
2018/08/01 00:00:00
2018/8/1 9:00:00
2018/8/1 ,几万条里会有那么3-4个,2018-10-24 星期日 下午 9:00:00
2018-10-24 星期日 下午 23:00:00.
问:如何查询出字段T_date 中日期大于2018年3月1日的所有数据,最低限度是要查出除了含有2018-10-24 星期日 下午 9:00:00
2018-10-24 星期日 下午 23:00:00这两种格式的所有数据

Oracle数据库中如何查询日期大于2018年3月1日的所有数据
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
4条回答 默认 最新
- 才沐木 2018-12-07 10:16关注
select * from (select replace(replace(replace(t.T_dateFormat, '/'), ' '), ':') T_dateFormat, t.T_date, t.T_name, t.T_sex from (select case when t.T_date like '%/%' then to_char(TO_DATE(t.T_date, 'YYYY/MM/DD HH24:MI:SS'), 'YYYY/MM/DD HH24:MI:SS') when t.T_date like '%-%' then to_char(TO_DATE(t.T_date, 'YYYY/MM/DD HH24:MI:SS'), 'YYYY/MM/DD HH24:MI:SS') end as T_dateFormat, t.T_date, t.T_name, t.T_sex from T t where t.T_date not like '%星期%') t) t where t.T_dateFormat > '20180301000000'
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报