Get the App
SLTechnology News&Howtos  ›  Database  › 

Oracle time addition and subtraction

Shulou Source: shulou.com Published: 2022-06-01 05:29:34 09月27日 Update

1, function: ADD_MONTHS (DATE,INTEGER)-adds the specified time to a few months later

For example:

SELECT ADD_MONTHS (SYSDATE, 1) FROM DUAL;-the current time plus 1 month, that is, one month later. SELECT ADD_MONTHS (SYSDATE,-1) FROM DUAL;-the current time minus 1 month, that is, the time of one month ago.

2. Add or subtract the SYSDATE for one time.

For example:

SELECT SYSDATE + 1 FROM DUAL;-the current time plus 1 day, that is, the time after one day (the 1 unit here is the day). SELECT SYSDATE-1 FROM DUAL;-the current time minus 1 day, that is, the time one day ago. SELECT SYSDATE + 1 take 24 FROM DUAL;-the current time plus 1 hour, that is, the time after one hour. SELECT SYSDATE + 1-24-60 FROM DUAL;-current time plus 1 minute, that is, one minute later. SELECT SYSDATE + 1max 24 FROM DUAL; 60 FROM DUAL;-the current time plus 1 second, that is, the time after one second.

By the same token, if it is minus (-), it will push forward a set time.

3,INTERVAL

The usage of INTERVAL is:

SELECT SYSDATE + /-INTERVAL 'N'TIMEUNIT FROM DUAL

Description:

N: numbers, that is, how much time to add or subtract, there must be single quotation marks.

TIMEUNIT is: unit of time. The preferred value is YEAR,MONTH,DAY,HOUR,MINUTE,SECOND.

For example:

SELECT SYSDATE + INTERVAL'1' DAY FROM DUAL;-- current time plus 1 month, that is, one month later. SELECT SYSDATE-INTERVAL'1' HOUR FROM DUAL;-- current time minus 1 hour, that is, one hour ago.

Tags: Time hour one month later unit function diva quotation mark number Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Shulou Technology MariaDB Huawei OPPO Reno