Number Function in SQL

Number Functions are :

  • ROUND – round the value to specified decimal.
  • TRUNC – truncate value to specified decimal.
  • MOD – returns remainder of division.
Function Result
Round(  45. 926 ) 46
Trunc( 45.926 ) 45
mod( 1600, 300 ) 100

Query : SELECT round( 50.4 ) from dual;

Examples : 

Function Result
round(  50.5 ) 51
round(  454.6565 ) 455
round(  454.6565 , 1 ) 456.7
round(  454.6565 , 2 ) 456.66
trunc(  454.6565 ) 456
trunc(  5000.7878 ) 5000
mod( 1000, 2 ) 0
mod(  1250, 2 ) 0

 

Question : Display the even and odd salary of employee.

Query for even  : SELECT * FROM emp WHERE mod( sal , 2 ) = 0

Query for odd  : SELECT * FROM emp WHERE mod( sal , 2 ) > 0