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

Date functions commonly used in Oracle

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

Share

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

-- 1. LAST_DAY function: find the last day of the month where the specified date is located

SELECT LAST_DAY (TO_DATE ('2014-12-02 camera camera YYYYMMI DD') FROM DUAL

2. Ask what day of the week the specified date is

SELECT TO_CHAR (TO_DATE ('1989-01-05),' DAY') FROM DUAL

3. What week of this year is the appointed date?

SELECT TO_CHAR (TO_DATE ('1989-01-05),' WW') FROM DUAL

4. Ask for the specified date to be the week of this month

SELECT TO_CHAR (TO_DATE ('1989-01-05) camera YYYYMMMI DD'),' W') FROM DUAL

-- 5. MONTHS_BETWEEN function: used to find the number of months between two dates. The result may be a decimal.

SELECT MONTHS_BETWEEN (TO_DATE ('1989-02-06)), TO_DATE (' 1989-01-05)) FROM DUAL

-- 6. The NEXT_DAY function, with the second parameter 1 for the next Sunday, 2 for Monday, 6 for Friday, 7 for Saturday / you can also use Monday-Sunday or the abbreviation / Mon-Sun

SELECT NEXT_DAY (SYSDATE,'2') FROM DUAL

Note: if you use MONDAY parameters, you need to modify the date language format first.

ALTERSESSIONSET NLS_DATE_LANGUAGE='AMERICAN'

SELECT NEXT_DAY (SYSDATE,'MONDAY') FROM DUAL

-- in Chinese language format, you can also use the day of the week to query.

ALTERSESSIONSET NLS_DATE_LANGUAGE='SIMPLIFIED CHINESE'

SELECT NEXT_DAY (SYSDATE,' Sunday') FROM DUAL

-- 7. ADD_MONTHS function: increase the month to find the date

SELECT ADD_MONTHS (TO_DATE (2000-01-29) FROM DUAL

-- 8. TREUC function: truncates to the nearest date (in days), returns the date type, and ignores it if the date contains hours, minutes and seconds

SELECT TRUNC (TO_DATE ('1989-01-05 11 lav 27 purl 35 mm')) FROM DUAL

-- 9. ROUND function: if the specified date exceeds the 15th of the current month, the 1st of the next month is displayed, otherwise the 1st of the month is displayed

SELECT ROUND (TO_DATE ('2000-01-09) camera YYYYMMMI DD'),' MONTH') FROM DUAL

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: 0

*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