Oracle obtains the date after a certain interval

Source: Internet
Author: User

Oracle has the following requirements to obtain the date after a certain interval: 1) display the time after the current 1.5 days. 2) display the time six hours later. 3) display the time six months later. 4) display the time after the current 10 years. Www.2cto.com, of course, we can use the sysdate conversion to add or subtract operations. In addition to the conventional method, Oracle also provides a function that can be used to represent a period of time interval, they are NUMTODSINTERVAL and NUMTOYMINTERVAL. Function expression after 1.5 days: NUMTODSINTERVAL (1.5, 'day') [SQL] SELECT NUMTODSINTERVAL (1.5, 'day') FROM DUAL; Result: NUMTODSINTERVAL (1.5, 'day') -------------------------------------- + 000000001 12:00:00. 000000000 function representation after 6 hours www.2cto.com: NUMTODSINTERVAL (6, 'hour ') [SQL] SELECT NUMTODSINTERVAL (6, 'hour') FROM DUAL; Result: NUMTODSINTERVAL (6, 'hour') ---------------------------------------- + 000000000 06:00:00. function expression after 6 months of 000000000: N UMTOYMINTERVAL (6, 'month') [SQL] SELECT NUMTOYMINTERVAL (6, 'month') FROM DUAL; the result is as follows: NUMTOYMINTERVAL (6, 'month ') ------------------------------ + 000000000-06 10 years later: NUMTOYMINTERVAL (10, 'Year') [SQL] SELECT NUMTOYMINTERVAL (10, 'Year') FROM DUAL; the result is as follows: NUMTOYMINTERVAL (10, 'Year') -------------------------------------- + 000000010-00 based on this, we can easily obtain the answers to the above four questions: 0) current time [SQL] SELECT TO_CHAR (SYSDATE, 'yyyy-MM-DD HH24: MI: ss') from dual; the result is as follows: TO_CHAR (SYSDATE, 'yy ----------------- 20:54:48 1) shows the time after 1.5 days. [SQL] SELECT TO_CHAR (SYSDATE + NUMTODSINTERVAL (1.5, 'day'), 'yyyy-MM-DD HH24: MI: ss') FROM DUAL; the result is as follows: TO_CHAR (SYSDATE + NUM-------------------2013-01-29 08:55:20 2) shows the time that is six hours later. [SQL] SELECT TO_CHAR (SYSDATE + NUMTODSINTERVAL (6, 'hour '), 'yyyy-MM-DD HH24: MI: ss') FROM DUAL; the result is as follows: TO_CHAR (SYSDATE + NUM-------------------2013-01-28 02:55:30 3) shows the time from now 6 months later. [SQL] SELECT TO_CHAR (SYSDATE + NUMTOYMINTERVAL (6, 'month'), 'yyyy-MM-DD HH24: MI: ss') FROM DUAL; www.2cto.com the result is as follows: TO_CHAR (SYSDATE + NUM-------------------2013-07-27 20:55:39 4) shows the time from now 10 years later. [SQL] SELECT TO_CHAR (SYSDATE + NUMTOYMINTERVAL (10, 'Year'), 'yyyy-MM-DD HH24: MI: ss') FROM DUAL; Result: TO_CHAR (SYSDATE + NUM-------------------2023-01-27 20:55:47
 

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.