在sqlplus / Oracle中将时代转换为日期 [英] Convert epoch to date in sqlplus / Oracle

查看:129
本文介绍了在sqlplus / Oracle中将时代转换为日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有下表:

SQL> desc recording
 Name                 Null?    Type
 -------------------- -------- ------
 CAPTUREID            NOT NULL NUMBER(9)
 STARTDATE            NOT NULL DATE
 ENDDATE                       DATE
 STATE                         NUMBER(1)
 ESTIMATEDENDTIME              NUMBER(13)

这是这个表的一行:

SQL> select * from recording where CAPTUREID=14760457;

 CAPTUREID STARTDATE           ENDDATE             STATE ESTIMATEDENDTIME
---------- ------------------- ------------------- ----- ----------------
  14760457 29/09/2010 08:50:01 29/09/2010 09:52:04     0    1285746720000

我很确定这有以前被问过这么多次,但是迄今为止我发现的所有解决方案并没有真正起作用,所以...如何从原始的时代表格转换 ESTIMATEDENDTIME 在SQLPLUS中的单个查询中的 DD / MM / YYY HH:MI:SS 格式?

I'm pretty sure that this has been asked so many times before, but all the solutions I've found so far didn't really work, so... How do I convert ESTIMATEDENDTIME from its original epoch form to a DD/MM/YYY HH:MI:SS format in a single query in SQLPLUS?

谢谢!

推荐答案

在Oracle中,将X添加到DATE将在十天后返回DATE。

In Oracle, adding X to a DATE will return you a DATE X days later.

如果ESTIMATEDENDTIME是自Epoch以来的毫秒,那么您可以执行

If ESTIMATEDENDTIME is milliseconds since Epoch then you could do

DATE '1970-01-01' + ( 1 / 24 / 60 / 60 / 1000) * ESTIMATEDENDTIME

然后使用to_char来实现正确生成日期的格式。例如:

and then use to_char to achieve the correct format of the resulting date. e.g:

SELECT 
  captureid
, startdate
, enddate
, state
, estimatedendtime
, DATE '1970-01-01' + ( 1 / 24 / 60 / 60 / 1000) * estimatedendtime AS estimatedenddate
FROM recording

这篇关于在sqlplus / Oracle中将时代转换为日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆