trunc() function in Oracle learning

Reprinted: https://www.cnblogs.com/linjiao/p/6394087.html

ORACLE TRUNC() function

TRUNC(): Similar to the interception function, intercepts the input data according to the specified format.

1.【trunc(for dates)】TRUNC() function handles dates

    Syntax format: TRUNC(date[,fmt])

  Where: date is a date value; fmt is the date format.

    The date will be truncated in the specified date format; omit it to truncate from the nearest date.

   Example:

   select trunc(sysdate) from dual;–2017/2/13, return the current time
   select trunc(sysdate,'yy') from dual;–2017/1/1, return the first day of the current year
   select trunc(sysdate,'mm' ) from dual;–2017/2/1, returns the first day of the month
   select trunc(sysdate,'d') from dual;–2017/2/12, returns the first day of the current week, which is Sunday
   select trunc(sysdate ,'dd') from dual;–2017/2/13, returns the current date, today is 2017/2/13
   select trunc(sysdate ,'HH24') from dual;–2017/2/13 15:00:00, Return the start time of this hour
   select trunc(sysdate ,'MI') from dual;–2017/2/13 15:13:00, return the start time of this minute

2.【TRUNC(for number)】TRUNC() function handles number type numbers

    Syntax format: TRUNC(number[,decimals])

    Among them: number is the value to be truncated; decimals indicates the number of digits after the decimal point to be retained, optional, if it is ignored, all the decimal parts will be truncated.

    Note: Data is not rounded during truncation.

    Example:

    select trunc(123.567,2) from dual;–123.56, truncate the specified number of digits to the right of the decimal point;
    select trunc(123.567,-2) from dual;–100, the second parameter can be negative, indicating that the left side of the decimal point is truncated The part after the specified number of digits is truncated, that is, it is marked as 0;
    select trunc(123.567) from dual;–123, the part after the decimal point is truncated by default;

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325591114&siteId=291194637
Recommended