如何从日期为01-01-9999的oracle的date字段中获取时间(以毫秒为单位) [英] how to get time in millisecond from date field of oracle for the date 01-01-9999

查看:57
本文介绍了如何从日期为01-01-9999的oracle的date字段中获取时间(以毫秒为单位)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从oracle的date字段中获取日期"01-01-9999"的毫秒数.

I want to get milliseconds from date field of oracle for date "01-01-9999".

我创建了以下代码块来实现相同的目的.

I have created below block to achieve the same.

set serveroutput on;
declare
    base_point constant timestamp := to_timestamp_tz('01-JAN-1970 00:00:00.000+00:00', 'DD-Mon-RR HH24:MI:SS.FFTZH:TZM') AT TIME ZONE 'UTC';
    now timestamp := to_timestamp_tz('01-01-2099 00:00:00.000+00:00', 'DD-MM-RR HH24:MI:SS.FFTZH:TZM') AT TIME ZONE 'UTC';
    -- now constant timestamp := systimestamp AT TIME ZONE 'UTC' ;
    n number;
begin

  select to_timestamp_tz(to_char(todate,'DD-MM-YY HH24:MI:SS')||'.000+00:00','DD-MM-YY HH24:MI:SS.FFTZH:TZM')
  into now
   from t_table where ACCOUNTID = 'ACC001124211';

 DBMS_OUTPUT.put_line(' now :'||now);

 n := (
                  ((extract(day    from (now-base_point)))*86400)
                + ((extract(hour   from (now-base_point)))*3600)
                + ((extract(minute from (now-base_point)))*60)
                + ((extract(second from (now-base_point))))
           ) * 1000;

           DBMS_OUTPUT.put_line(' n :'||n);
end;
/

但是使用上面的代码块,我得到的值是 4070908800000 ,它等于日期 1/1/2099 ,但是我表中的实际日期是 01-01-9999

but using above block I am getting value as 4070908800000, which is equal to date 1/1/2099 but actual date in my table is 01-01-9999

请帮助我们使用日期字段获取精确的毫秒数

Can you please help us to get exact millisecond using date field

推荐答案

不需要 PL/SQL ,您可以使用普通的 SQL 来实现.

No need of PL/SQL, you could do it in plain SQL.

1970年1月1日以来,将日期转换为毫秒:

SQL> SELECT to_number(DATE '9999-01-01'
  2         - to_date('01-JAN-1970','DD-MON-YYYY')) * (24 * 60 * 60 * 1000) milliseconds
  3  FROM dual;

      MILLISECONDS
------------------
   253370764800000

SQL>

这篇关于如何从日期为01-01-9999的oracle的date字段中获取时间(以毫秒为单位)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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