总结一下用到过的数据库日期显示的sql
1: 将数据库中存的varchar2格式的数据如:20170223162343 转换成 2017-01-06 14:17:18
cre_dt='20161227'
cre_tm='173524'
select to_char(to_date(cre_dt,'yyyy-MM-dd'),'yyyy-MM-dd ')||to_char(to_date(cre_tm,'hh24:mi:ss'),'hh24:mi:ss') from 表名
|| 是将两个检索出来的结果拼接在一起 hh24:mi:ss' 表示时间是24小时制的
select to_date(cre_dt,'yyyy-MM-dd') from 表名 结果为 :2016/12/27 时间格式
select to_char(to_date(cre_dt,'yyyy-MM-dd'),'yyyy-MM-dd ') from 表名 结果为:2016-12-27 转表为char类型
select to_date(cre_tm,'hh24:mi:ss') from 表名 结果为: 2017/2/1 14:17:18 默认加上年月日 时间类型
select to_char(to_date(cre_tm,'hh24:mi:ss'),'hh24:mi:ss') from 表名 结果为: 14:17:18 不会默认加上年月日