How To Use Arithmetic function in Oracle
Arithmetic Functions Type
- ABS(n)
- CEIL(n)
- FLOOR(n)
- MOD(m, n)
- SIGN(n)
- SQRT(n)
- TRUNC(m, [n])
- ROUND(m, [n])
- EXP(n)
This function returns an absolute value of the column or the passed value.
Example
- Select ABS(-55)
- from dual;
CEIL(n)
This function finds the smallest integer greater than or equal to n. n can be a column name.
Example
- Select CEIL(salary) “CEIL(Salary)”
- from Employee
- where salary between 30000 to 50000;
FLOOR(n)
This function finds the largest integer less than or equal to the value n. n can be either a column or an expression.
Example
- Select FLOOR(salary), CEIL(88.9)
- from Employee
- where salary Between 30000 AND 50000;
MOD(m, n)
This function returns the reminder of m divided by n or m, if n = 0.
Example
- Select MOD(300, 45)
- from dual;
Power(m, n)
This function returns m raised to the power n. The second argument n must be an integer.
Example
- Select salary, power(salary, 2)
- from employee
- where dept_no = 104;
SIGN(n)
This function returns -1, if n is negative. It returns 1, if n is positive and it returns 0, if n is 0.
Example
- Select salary, SIGN(salary)
- from employee
- where dept_no = 101;
SQRT(n)
This function returns the square root of n. If the value n is NULL or negative, Null is returned.
Example
- Select Salary, SQRT(salary)
- from employee
- where dept_no = 105;
TRUNC(m, [n])
This function truncates the m or column to n decimal places. If n is omitted, it is truncated to no decimal places. If n is negative, numbers left of decimal places are truncated to 0.
Example
- Select trunc(80.345, 1), trunc(80.345, -1), trunc(80.345)
- from dual;
- Select salary, TRUNC ( SQRT (salary),2)
- From employee
- Where dept_no = 103;
ROUND(m, [n])
This function rounds the column, expression or value m to n decimal places. If n is omitted, it is round off. If n is a negative number to left, the number is round off.
Example
- Select ROUND(80.345, 1), ROUND(80.345, -1), ROUND(80.345)
- from dual;
- Select salary, ROUND(SQRT(salary), 2)
- from employee
- where dept_no=102;
Exp(n)
This function returns e raised to the nth power.
Example
- Select EXP(4)
- from dual;
Summary
Thus, we learnt, how to use arithmetic functions in Oracle with the examples.