Convert epoch to date in sqlplus / Oracle(在 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 将在 X 天后返回 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 中将纪元转换为日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 sqlplus/Oracle 中将纪元转换为日期


- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
- 在SQL中,如何为每个组选择前2行 2021-01-01
- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- 导入具有可变标题的 Excel 文件 2021-01-01
- 更改自动增量起始编号? 2021-01-01
- SQL 临时表问题 2022-01-01