The ABS function returns NULL if the passed value expression
evaluates to NULL. The datatype of the result is the same as the
passed value expression and supports scaled values of these data
types: TINYINT, SMALLINT, INTEGER, BIGINT, REAL, FLOAT, DOUBLE
PRECISION, INTERVAL, DECIMAL, NUMERIC and NUMBER.
The absolute value function (ABS) returns NULL if the value
expression evaluates to NULL. If the value expression evaluates
to a value less than zero then that value is negated so that
a positive value is returned. Otherwise the value is returned
unchanged. For instance, ABS (-1) will return the value 1.
ABS (a) is equivalent to the CASE expression
case
when a < 0 then - a
else a
end
Example: Using the ABS function on an INTERVAL result of a date
subtraction.
SQL> select
cont> ABS ((birthday - current_date) year(3))
cont> from employees
cont> order by employee_id
cont> limit to 10 rows;
054
047
047
064
068
062
044
069
050
074
10 rows selected
Example: Using ABS within a statistical function
SQL> -- what is the average time in a job for each employee
SQL> -- exclude anyone on there first job
SQL> select
cont> employee_id,
cont> AVG (ABS (EXTRACT (MONTH FROM (job_start - job_end) month (4))))
cont> as "Average Job" edit using '--,---,--9.99" years"'
cont> from JOB_HISTORY
cont> where employee_id < '00200'
cont> group by employee_id
cont> having COUNT (*) > 1;
EMPLOYEE_ID Average Job
00164 14.00 years
00165 22.67 years
00166 20.00 years
00167 14.50 years
00168 26.33 years
00169 22.67 years
...etc...
00197 26.33 years
00198 37.00 years
00199 35.00 years
30 rows selected
%RDB-I-ELIM_NULL, null value eliminated in set function