Abs
returns the absolute value of a number.
This Oracle tutorial explains how to use the Oracle/PLSQL ABS function.
The syntax for the Oracle/PLSQL ABS function is:
ABS( number )
number
is the number to convert to an absolute value.
The following code shows how to use ABS function with constant values.
SQL> select abs(-1) from dual;
-- from w ww . j a va 2 s . com
ABS(-1)
----------
1
SQL> select ABS(10) from dual;
ABS(10)
----------
10
SQL> select ABS(-10) from dual;
ABS(-10)
----------
10
SQL>
Using ABS function with column names.
create table TestTable(
ID VARCHAR2(4 BYTE) NOT NULL,
MyNumber Number(8,2)-- w w w.j av a 2s . c o m
);
insert into TestTable (ID, MyNumber)values('1',12.12);
insert into TestTable (ID, MyNumber)values('1',-1.1);
insert into TestTable (ID, MyNumber)values('1',1.1);
SQL> select myNumber from testTable;
MYNUMBER
----------
12.12
-1.1
1.1
SQL>
SQL> select abs(myNumber) from testTable;
ABS(MYNUMBER)
-------------
12.12
1.1
1.1
SQL>