Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to handle leap seconds in Oracle

Tags:

oracle

Tonight there is going to be a leap second added to the clocks and there will be 61 seconds in the last minute of the last hour of the day.

2015-06-30 23:59:60

However, Oracle only supports up to 60 seconds in a minute:

TO_DATE( '2015-06-30 23:59:60', 'YYYY-MM-DD HH24:MI:SS' )    

Errors with:

ORA-01852: seconds must be between 0 and 59

and

SELECT TO_DATE( '2015-06-30 23:59:59', 'YYYY-MM-DD HH24:MI:SS' ) + INTERVAL '1' SECOND AS Incr_Second_Before,
       TO_DATE( '2015-07-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS' ) - INTERVAL '1' SECOND AS Decr_Second_After
FROM   DUAL

Gives the output:

|     INCR_SECOND_BEFORE |      DECR_SECOND_AFTER |
|------------------------|------------------------|
| July, 01 2015 00:00:00 | June, 30 2015 23:59:59 |

Is there any way to handle a leap second in Oracle?

like image 617
MT0 Avatar asked Jun 30 '15 10:06

MT0


People also ask

How does Linux ntpd handle leap seconds?

A stratum 4 ntp server may get the leap indicator over an hour after the start of the day. When a Linux ntpd gets the leap indicator it uses adjtimex (2) to tell the kernel that a leap second is going to be inserted (or deleted) at midnight UTC. The NTP daemon is not responsible for actually handling the leap second, it defers that to the kernel.

How much notice do we have of a leap second?

We will always have at least three months' notice of a leap second but they are essentially unpredictable because the earth wobbles. The last leap second was at the end of June 2012 and the next one is at the end of June 2015. So far we haven’t had any short days, but it’s possible.

When was the last time the UK had a leap second?

The last leap second was at the end of June 2012 and the next one is at the end of June 2015. So far we haven’t had any short days, but it’s possible.

What is Oracle lag () function?

Oracle LAG 1 Introduction to Oracle LAG () function. Oracle LAG () is an analytic function that allows you to access the row at a given offset prior to the current row without ... 2 Oracle LAG () function examples. ... 3 A) Using Oracle LEAD () function over a result set example. ... 4 B) Using Oracle LAG () function over partitions example. ...


1 Answers

From MOS-

Insert leap seconds into a timestamp column fails with ORA-01852 (Doc ID 1553906.1)

APPLIES TO:

Oracle Database - Enterprise Edition - Version 8.1.7.4 and later

Oracle Database - Standard Edition - Version 8.1.7.4 and later

Information in this document applies to any platform.

SYMPTOMS:

An attempt to insert leap seconds into a timestamp column, fails with: ORA-01852: seconds must be between 0 and 59

CAUSE

It is not possible to store >59 sec value in a date or timestamp datatype

SOLUTION

To workaround this issue, the leap second record can be stored in a varchar2 datatype instead e.g.

SQL> create table test (val number, t varchar2(30));

Table created.

SQL> insert into test values(123, '2012-06-30T23:59:60.000000Z');

1 row created.

Not the best solution, but the only solution.

like image 65
AnBisw Avatar answered Oct 31 '22 23:10

AnBisw