Oracle timestamp added value

Source: Internet
Author: User

Oracle timestamp added value
During my work, I encountered this problem. The session table needs to use the timestamp field. When the timestamp field is updated, the question is displayed. For example, the validity period of the session needs to be increased by 1 hour.
Using iimestamp + 1/24 will lose the precision of the second, and it will become the date type after the increase. After research, we found that oracle has a function called NUMTODSINTERVAL, which can solve this problem. The following two examples illustrate how to use this function.

Add one 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 version of numtodesignterval is described as follows:

NUMTODSINTERVAL converts n to an interval day to second literal. the argument n can be any NUMBER value or an expression that can be 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'

In terms of interpretation, the NUMTODSINTERVAL function can also increase the values of day and sesond. (to reduce the processing value, you only need to add "-" before the number.) It is a very powerful function. In addition, if you want to add a year or month,
Select the NUMTOYMINTERVAL function.

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.