Oracle timestamp type added value problem

Source: Internet
Author: User

In the work I encountered such a problem, the session table needs to use the timestamp field, in the timestamp field updates appear as a problem, such as the need to increase the duration of the session 1 hours.
The use of Systimestamp + 1/24 will lose the accuracy of the second, the feeling increases after the appearance of the date type. A study has found that Oracle has a function calledNumtodsinterval, this problem can be solved.The following two examples show how to use theThis function

Add an hour

SELECT To_char (systimestamp + numtodsinterval(1,' Hour '), ' Yyyy-mm-dd HH24:mi:ss:ff '), To_char (Systimestamp, 'yyyy-mm-dd HH24:mi:ss:ff') from dual;

Add one minute

SELECT To_char (systimestamp + numtodsinterval(1,'minut'), ' Yyyy-mm-dd HH24:mi:ss:ff '), to_ char (Systimestamp, ' Yyyy-mm-dd HH24:mi:ss:ff ') from dual;

The original interpretation of Numtodesignterval is as follows:

Numtodsinterval converts n to a INTERVAL day to SECOND literal. The argument n can is any number of value or an expression, the can is implicitly converted to a number value. The argument interval_unit can be of CHAR, VARCHAR2, NCHAR, or NVARCHAR2 datatype. The value for interval_unit specifies the unit of N and must resolve to one of the following String values:

    • ' Day '
    • ' HOUR '
    • ' MINUTE '
    • ' SECOND '

From the interpretation, thenumtodsinterval function can also handle the increase in the value of day and Sesond, which is a very powerful function, as long as the "-" is added to the "-" before the number. In addition, if you need to increase the number of years or months,
To select the Numtoyminterval function

Oracle timestamp type added value problem

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.