Using Numeric Functions

Previous
Previous
Next
Next

Oracle Database XE provides a set of numeric functions that you can use in your SQL statements to manipulate numeric values. With numeric functions, you can round to a specified decimal, truncate to a specified decimal, and return the remainder of a division on numeric data.

Example: Using SQL Numeric Functions shows the use of numeric functions on numeric data.

Using SQL Numeric Functions

-- you can use the ROUND function to round off numeric data, in this case to
-- two decimal places
SELECT employee_id, ROUND(salary/30, 2) "Salary per day" FROM employees;

-- you can use the TRUNC function to truncate numeric data, in this case to
-- 0 decimal places; 0 is the default so TRUNC(salary/30) would be same
SELECT employee_id, TRUNC(salary/30, 0) "Salary per day" FROM employees;

-- use the MOD function to return the remainder of a division
-- MOD is often used to determine is a number is odd or even
-- the following determines whether employee_id is odd (1) or even (0)
SELECT employee_id, MOD(employee_id, 2) FROM employees;