Introduction SQL

Basic SQL

SQL Constraints

Advance SQL

SQL Joins

SQL Function


SQL ROUND, TRUNC Function - Round to two decimal places


SQL ROUND Function

SQL ROUND function return the round number of specified nth number of decimal place.

Supported Oracle SQL Version :

  • Oracle 8i
  • Oracle 9i
  • Oracle 10g
  • Oracle 11g
  • Oracle 12c

Syntax :

ROUND(n, decimal_number)

n is a number to return a round number and
decimal_number is specified nth of decimal place to a rounded.

Example :

Considering following example SQL ROUND function.

SQL> SELECT ROUND(10.5454,2) "Round" FROM DUAL;

     Round
----------
     10.55

SQL> SELECT ROUND(5.1234,2) "Round" FROM DUAL;

     Round
----------
      5.12

SQL> SELECT ROUND(5.999,1) "Round" FROM DUAL;

     Round
----------
         6

SQL> SELECT ROUND(5.8989,1) "Round" FROM DUAL;

     Round
----------
       5.9

SQL TRUNC Function

SQL TRUNC function return the truncated number of specified nth number of decimal place.

Supported Oracle SQL Version :

  • Oracle 8i
  • Oracle 9i
  • Oracle 10g
  • Oracle 11g
  • Oracle 12c

Syntax :

TRUNC(n, decimal_number)

n is a number to return a truncated number and
decimal_number is specified nth of decimal place to a truncate.

Example :

Consider following example take n number, return the square root of the number.

SQL> SELECT TRUNC(10.1234,1) "TRUNC" FROM DUAL;

     TRUNC
----------
      10.1

SQL> SELECT TRUNC(10.1234,2) "TRUNC" FROM DUAL;

     TRUNC
----------
     10.12

SQL> SELECT TRUNC(10.1234,3) "TRUNC" FROM DUAL;

     TRUNC
----------
    10.123