Thursday 30 May 2013

Number Functions in SQL

  • ROUND : Rounds values to specified decimal.
                   ROUND(45.878,2)       ------------------->   45.88
  • TRUNC  :  Truncates value to specified decimal.
                   TRUNC(45.878,2)       -------------------->   45.87
  • MOD : Returns remainder of division.
                   MOD(1600,300)          -------------------->  100

Example:


ROUND
The Round Function rounds the column, expression, or value to n decimal place.
If the second argument is 0 or is missing, the value is round to zero decimal place.
If the second argument is 2, the value is rounded to two decimal places.
If the second argument is -2, the value is rounded to two decimal places to the left.


TRUNC
The TRUNC function truncates the column, expression, or value to n decimal places.
If the second argument is 0 or is missing, the value is truncated to zero decimal places.
If the second argument is 2, the value is truncated to two decimal places.
If the second argument is -2, the value is truncated to two decimal places to the left.






No comments:

Post a Comment