Showing posts with label Oracle PL/SQL Mathematical functions. Show all posts
Showing posts with label Oracle PL/SQL Mathematical functions. Show all posts

Oracle PL/SQL - SIGN function

In this tutorial we will explain how to use the Oracle PL/SQL SIGN function with syntax and examples

SIGN Function : 

Syntax : SIGN(input_number) ;

  • In Oracle PL/SQL , SIGN is a inbuilt function which is used to determine the sign of a give number.
  • Returns -1 if input_number is < 0
  • Returns 1 if input_number is > 0
  • Returns 0 if input_number is = 0
  • Return type is number and is either -1 ,1 or 0.


EXAMPLE :1 (When Input number is < 0 )

SELECT SIGN(-100) FROM DUAL;

SIGN
--------------------
-1
EXAMPLE :2 ( When Input number is > 0)

SELECT SIGN(143.12) FROM DUAL;

SIGN
--------------------
1
EXAMPLE :3 (When Input number is = 0 )

SELECT SIGN(0) FROM DUAL;

SIGN
--------------------
0

Oracle PL/SQL - ABS function

In this tutorial we will explain how to use the Oracle PL/SQL ABS function with syntax and examples

ABS Function : 

Syntax : ABS ('input_number');

  • In Oracle PL/SQL ABS function returns the absolute value of the input number that is passed to the function.
  • input_number is of numeric datatype.
  • return type is same as the input datatype.

EXAMPLE 1 :

SELECT ABS(-143) "Absolute_value" FROM DUAL;

  Absolute_value
-----------------
             143
EXAMPLE 2 :

SELECT ABS(143.14) "Absolute_value" FROM DUAL;

  Absolute_value
-----------------
           143.14