Friday, 1 November 2019

ABS function in SQL

Case Study:

Get only positive Values



Practice Table:

create table plch_employees (
   id    integer primary key
, name  varchar2(40)
, gender char(1)         
)
/
insert into plch_employees values (-100, 'Mr. John Doe','M')
/
insert into plch_employees values (-200, 'Mrs. Jane Doe','F')
/
insert into plch_employees values (300, 'Ms. Julie Doe','F')
/
insert into plch_employees values (-400, 'Mr. Jack Doe','M')
/
insert into plch_employees values (500, 'Dr. James Doe','M')
/
insert into plch_employees values (600, 'Jonathan Doe','M')
/
insert into plch_employees values (700, 'Jeff Jr. Doe','M')
/
commit
/



ABS
Syntax
Purpose

The ABS function returns the absolute value of a number, which will always be zero or a positive number.
This function takes as an argument any numeric data type or any nonnumeric data
type that can be implicitly converted to a numeric data type.

Examples


The following example returns the absolute value of -15:

SELECT ABS (-15) "Absolute"
FROM DUAL;
Absolute
----------
15

No comments:

Post a Comment

How To: Remove all rows from view object (VO) in OAF & ADF

This is the basic requirement when we are working with oracle OAF. In which we need to removed the all rows from the table. The best use ca...