Press ESC to close

How to use the ROUND, TRUNC and MOD function in Oracle sql. with examples.

ROUND function is used when you need to round decimal number to the closest one.

Round numbers:

ROUND Examples:
SELECT ROUND(45.923,2), ROUND(45.923,0),
ROUND(45.923,-1)
FROM   DUAL;

TRUNC function:

TRUNC function is required when you need to remove part of the decimals without rounding it.

TRUNC Example:

SELECT  TRUNC(45.923,2), TRUNC(45.923),
TRUNC(45.923,-2)
FROM   DUAL;

MOD Function:

MOD function is used to calculate the remainder number.

The MOD function is often used to determine if a value is odd or even.

MOD Example:

SELECT  MOD(5 ,2 ), 
MOD(1600 , 300 )
FROM   DUAL;

Mod Example 2:

SELECT last_name, salary, MOD(salary, 5000)
FROM   employees
WHERE  job_id = 'SA_REP';

Read More:

Leave a Reply