Date and number can be intercepted
For example, 2010-10-15, cut to the first day of 2010, that is, 2010-01-01,
such as 20.5, cut to 20
table of Contents
Cut-off date
You must first understand what the cut-off date is.
Assuming date=27-10-20
trunc(date,'yyyy'), get the first day of the year
Different from to_char();
如果 2020-05-12,你想获取2020,请用`to_char(date,'yyyy');`
获取05,`to_char(date,'mm')`
获取12,`to_char(date,'dd')`
trunc(date [, fmt ]) , return date
- fmt omit
output year, month and day - yyyy
returns to the first day of the year等于 SYYYY YYYY YEAR SYEAR YYY YY Y
- mm, the first day of the month. equal
MONTH MON MM RM
- ww. A date with the same day of the week as the first day of the year.
For example, 2020-12-23, the first day of the first year is Wednesday, and 2020-12-23 happens to be Wednesday, output it;
2020-12-22, the first day of the first year is Wednesday, output 2020-12-16 (The 16th is Wednesday) The
output date <= the specified date. - DD, annual income, equal to
DDD DD J 和省略fmt
- day, the first day of the week (Sunday), equal to
DAY DY D
Intercepted numbers
It's just interception, not rounding up.
trunc(n1,[,n2]) , return number
-
n2 can be omitted. Intercept the integer part like this
-
n2 is positive, truncated to n2 digits after the decimal point
-
N2 digits are negative, n2 digits before the decimal point are set to 0
Reference from: oracle official document
https://docs.oracle.com/en/database/oracle/oracle-database/19/sqlrf/TRUNC-number.html#GUID-911AE7FE-E04A-471D-8B0E-9C50EBEFE07D