oracle 如何在 PL/SQL 中获取纪元?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30211623/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 02:51:41  来源:igfitidea点击:

How to get the epoch in PL/SQL?

sqloracle

提问by Ajay

I want to insert the current time in millis ( epoch ) to a table. Is there any built in function that I can use which gives me the time in epoch?

我想将当前时间(以毫秒为单位)插入到表中。是否有任何内置功能可以使用,让我在 epoch 中获得时间?

回答by ennovation

This will give you the milli seconds since 01-Jan-1970:

这将为您提供自 1970 年 1 月 1 日以来的毫秒数:

select (sysdate - to_date('01-Jan-1970', 'dd-Mon-yyyy')) *24*60*60*1000 from dual

select (sysdate - to_date('01-Jan-1970', 'dd-Mon-yyyy')) *24*60*60*1000 从双

回答by Lalit Kumar B

Keeping in mind the timezone:

记住时区

SQL> SELECT
  2     EXTRACT(DAY FROM (from_tz(CAST(SYSDATE AS TIMESTAMP), SESSIONTIMEZONE) AT TIME ZONE 'UTC' -TIMESTAMP '1970-01-01 00:00:00 +00:00'))*86400+
  3     EXTRACT(HOUR FROM (from_tz(CAST(SYSDATE AS TIMESTAMP), SESSIONTIMEZONE) AT TIME ZONE 'UTC' -TIMESTAMP '1970-01-01 00:00:00 +00:00'))*3600+
  4     EXTRACT(MINUTE FROM (from_tz(CAST(SYSDATE AS TIMESTAMP), SESSIONTIMEZONE) AT TIME ZONE 'UTC' -TIMESTAMP '1970-01-01 00:00:00 +00:00'))*60+
  5     EXTRACT(SECOND FROM (from_tz(CAST(SYSDATE AS TIMESTAMP), SESSIONTIMEZONE) AT TIME ZONE 'UTC' -TIMESTAMP '1970-01-01 00:00:00 +00:00')) date_to_epoch
  6  FROM dual;

DATE_TO_EPOCH
-------------
   1431513604