oracle database trunc function, rounding

 Trunc function (for date)

  Usage one (for date):

  The date value truncated for the specified element.

  The syntax is as follows:

  TRUNC(date,[fmt])

  Parametric analysis:

  date

  a date value.

  fmt

  The date format that will be truncated by the specified element format. Omit it to cut off by the most recent date.

  Not much to say, just look at the example! You will understand after reading it.

  Example:

  Take today as an example, today is September 10, 2010. (It just happens that today is Teacher's Day. I wish the teachers a happy holiday here!)

  SELECT trunc(sysdate,'mm')FROM dual

  Returns 2010-9-01 (that is, returns the first day of the month) SELECT trunc(sysdate,'yy')FROM dual

  Returns the first day of the year 2010-1-1 SELECT trunc(sysdate,'dd')FROM dual

  Returns the day of 2010-9-10 SELECT trunc(sysdate,'day')FROM dual

  Returns the first day of the week 2010-9-5 SELECT trunc(sysdate)FROM dual

  Return to 2010-9-10 If you do not fill in the fmt parameter, the default is the current day

  PS:

  The output format of trunc(sysdate) is YYYY-MM-DD, but it rounds the time to zero of the current day, that is:

  SELECT to_char(trunc(sysdate),'YYYY-MM-DD HH24:mi:ss') FROM dual  返回2010-09-10 00:00:00

  ++ See more oracle convert character functions < http://www.syranmo.com/2010/09/09/oracle-ecimal-trunc/ >

  Usage two (for number):

  The TRUNC function returns the processed value. Its principle is similar to that of the ROUND function, except that this function does not perform corresponding rounding selection processing for the part before or after the specified decimal.

  but

  All cut off.

  The syntax is as follows:

  1TRUNC(number,[decimals])

  Parametric analysis:

  number

  The value to be truncated.

  decimals

  Indicates the number of digits after the decimal point to be retained. (Note: optional, omit it to truncate all decimal parts)

  The second parameter can be a negative number, which means that the part after the specified number of digits to the left of the decimal point is truncated

  Example:

  SELECT TRUNC(88.876,2) FROM dual

  返回88.87  SELECT TRUNC(88.876) FROM dual

  返回88  SELECT TRUNC(88.876,-1) FROM dual

  return 80

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326590446&siteId=291194637