oracle sql 语句 时间戳 转日期格式

1436346362189 时间戳长这样 要转换成 ’yyyy-MM-dd hh:mm:ss'格式

第1个回答  2015-11-25
select TO_DATE('1970-01-01','yyyy-mm-dd 24hh:mm:ss') + (1436346362189/86400 +TO_NUMBER(SUBSTR(TZ_OFFSET(sessiontimezone),1,3))/24) from dual;

试试看吧
第2个回答  2015-11-25
select to_char(时间戳字段, ’yyyy-MM-dd hh:mm:ss') from tablename追问

select to_char('1436346362189', 'yyyy-MM-dd hh:mm:ss') from dual;
自己验证一下可以吗?????

追答

create table test111(
id integer,
modifydatetime timestamp);
insert into test111 values(1, sysdate);
select to_char(modifydatetime, 'yyyy-MM-dd hh:mm:ss') from test111;
结果是
25-11月-15 04.33.05.000000 下午

直接执行select to_char('1436346362189', 'yyyy-MM-dd hh:mm:ss') from dual;应该会出错吧。

'1436346362189'这本身就是一个字符串了。

追问

对,本身就是一字符串,数据库存的就是时间戳转的字符串,由于我的问题描述的不够详细,这里补充一下,那个时间是字符串类型是VACHAR(50) ,java代码 System.currentTimeMillis() 获取时间戳,然后转成的字符串存储的

追答

select to_date('1970-01-01 00:00:00', 'yyyy-mm-dd hh24:mi:ss') + 1436346362189/(24*60*60*1000) from dual;

本回答被提问者和网友采纳