Oracle's trunc function

trunc (): function similar to interception, the interception of the data input by the specified format.
1, trunc () functions for date
syntax: trunc (date [, fmt] )
  wherein: date a date value; date format FMT.
The date will be the date specified format interception; ignored by most recent date intercepted.
Example:

select trunc (sysdate) from dual; - 2017/2/13, returns the current time, date when containing only minute and second are not included 
select trunc (sysdate, 'yy' ) from dual; - 2017/1/1, returns the first day then 
select trunc (sysdate, 'mm' ) from dual; - 2017/2/1, returns the first of the month 
select trunc (sysdate, 'd' ) from dual; - 2017/2/12, returns the first day of the current week, Sunday, i.e. 
select trunc (sysdate, 'dd' ) from dual; - 2017/2/13, returns the current date, today 2017/2/13 
SELECT the trunc (SYSDATE, 'HH24') from dual; - 2017/2/13 15:00:00, return to this starting time hours 
select trunc (sysdate, 'MI' ) from dual; - 2017/2/13 15:13:00, this minute return start time

2, trunc () function processing digital number
syntax: trunc (number [, decimals] )
where: number value to be taken to do the processing; decimals should be reserved specified number of digits after the decimal point, options, it ignores all the truncated the fractional part.
Note: No data taken when rounding.
Example:

select trunc (123.567,2) from dual; - 123.56, the specified number of digits after the decimal point to the right of clipping; 
SELECT the trunc (123.567, -2) from Dual; - 100, the second parameter may be a negative number, shows a left Specifies the number of digits after the decimal point truncated section, i.e., are referred to 0; 
SELECT the trunc (123.567) from Dual; - 123, the back part of the default truncating the decimal point;

  

Transfer: https://www.cnblogs.com/kliine/p/10727997.html

Guess you like

Origin www.cnblogs.com/shujk/p/12635587.html