Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Oracle time addition and subtraction

2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 287

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report