Oracle TRUNC () function usage, oracletrunc
TRUNC () function usage in Oracle
1. Processing date
TRUNC (date [, fmt]): truncates a date based on the fmt Format.
Select trunc (SYSDATE, 'D') from dual; -- select trunc (SYSDATE, 'mm') from dual on the first day of the week; -- select trunc (SYSDATE, 'q') from dual; -- select trunc (SYSDATE, 'y') from dual;
2. Used to process values
TRUNC (n1, n2): Used to intercept n1 Based on n2 and return the result. n2 can be omitted. The truncated value is not rounded.
Select trunc (98765.56789) from dual; -- n2 omitted. The default value is 0. The query result is: 98765 select trunc (98765.56789, 2) from dual; -- <span style = "font-family: Arial, Helvetica, sans-serif;"> n2 is omitted. The default value is 0. The query result is: </span> <span style = "font-family: Arial, Helvetica, sans-serif;"> 98765.56 </span> select trunc (98765.56789, 1) from dual; -- <span style = "font-family: Arial, Helvetica, sans-serif;"> n2 is omitted. The default value is 0. The query result is: </span> 98765.5 select trunc (98765.56789, 0) from dual; -- <span style = "font-family: Arial, Helvetica, sans-serif;"> n2 omitted, the default value is 0. The query result is: </span> 98765 select trunc (98765.56789,-1) from dual; -- <span style = "font-family: Arial, Helvetica, sans-serif; "> n2 omitted. The default value is 0. The query result is: </span> 98760 select trunc (98765.56789,-2) from dual; -- <span style = "font-family: Arial, Helvetica, sans-serif;"> n2 is omitted. The default value is 0 and the query result is: </span> 98700.
Certificate -------------------------------------------------------------------------------------------------------------------------------------------------
If you encounter any problems during your attempt or my code is incorrect, please correct me. Thank you very much!
Contact: david.louis.tian@outlook.com
Copyright @: reprinted, please indicate the source!
Oracle trunc () function usage
1. select trunc (sysdate) from dual -- 2011-3-18 today's date is 2011-3-18
2. select trunc (sysdate, 'mm') from dual -- 2011-3-1 returns the first day of the current month.
3. select trunc (sysdate, 'yy') from dual -- 2011-1-1 return the first day of the current year
4. select trunc (sysdate, 'dd') from dual -- 2011-3-18 return current year month day
5. select trunc (sysdate, 'yyyy') from dual -- 2011-1-1 return the first day of the current year
6. select trunc (sysdate, 'D') from dual -- 2011-3-13 (Sunday) returns the first day of the current week
7. select trunc (sysdate, 'hh') from dual -- 2011-3-18 14:00:00 current time is
8. select trunc (sysdate, 'mi') from dual -- 2011-3-18 14:41:00 the TRUNC () function has no precision in seconds.
The oracle trunc () function provides detailed answers and examples for date and time?
Trunc Function (with dates)
In Oracle/PLSQL, the trunc function returns a date truncated to a specific unit of measure.
In oracle, The trunc function returns a date value intercepted by a specific unit of measurement.
The syntax for the trunc function is:
Syntax:
Trunc (dat1e, [format])
Da1te is the date to truncate.
Da1te is the date to be truncated
Format is the unit of measure to apply for truncating. if the format parameter is omitted, the trunc function will truncate the date to the day value, so that any hours, minutes, or seconds will be truncated off.
Format is the unit of measurement (similar to the precision in a number) based on the truncation ). If format is omitted, date1 returns the date value of the current day, that is, only the date is retained, and the time is 0:00:00.
Below are the valid format parameters:
The following are valid parameter values:
UnitValid format parameters
Year] SYYYY, YYYY, YEAR, SYEAR, YYY, YY, Y
ISO Year: IYYY, IY, I
Quarter] Q
Month] MONTH, MON, MM, RM
Week] WW
IW
W] W
Day: DDD, DD, J
Start day of the week] DAY, DY, D
Hour] HH, HH12, HH24
Minute: MI
Applies:
Oracle 8i, Oracle 9i, Oracle 10g, Oracle 11g
For example:
Trunc (to_date ('22-AUG-03 '), 'Year') wo'd return '01-JAN-03'
Trunc (to_date ('22-AUG-03 '), 'q') wo'd return '01-JUL-03'
Trunc (to_date ('22-AUG-03 '), 'month') wo'd return '01-AUG-03'
Trunc (to_date ('22-AUG-03 '), 'ddd') wo'd return '22-AUG-03'
Trunc (to_date ('22-AUG-03 '), 'day') wo'd return '17-AUG-03'... the remaining full text>