Number Functions | Round, Trunc , Mod, Power, Cos, Tan, Sqrt

Number functions

Number functions accept numeric input and return numeric values. This section describes some ofthe number functions.

The number functions available in Oracle are:

ABS  ACOS ASIN ATAN ATAN2 BITAND CEIL COS COSH EXP FLOOR LN LOG 
MOD POWER ROUND (number) SIGN SIN SINH SQRT TAN TANH TRUNC (number) 
 
ABS
ABS returns the absolute value of n.
The following example returns the absolute value of -87:

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

Output:
 Absolute
----------
        87

ACOS
ACOS returns the arc cosine of n. Inputs are in the range of -1 to 1, and outputs are in the range of 0 to pi and are expressed in radians.
The following example returns the arc cosine of .3:

SELECT ACOS(.3)"Arc_Cosine" FROM DUAL;

          Output:
Arc_Cosine
----------
1.26610367

Similar to ACOS, you have ASIN (Arc Sine), ATAN (Arc Tangent) functions.

CIEL
Returns the lowest integer above the given number.
Example:
The following function return the lowest integer above 3.456;

Select ciel(3.456) “Ciel” from dual;

Output:
Ciel
---------
        4
FLOOR
Returns the highest integer below the given number.
Example:
The following function return the highest integer below 3.456;

Select floor(3.456) “Floor” from dual;
         
Output:
Floor
------------
        3

COS
Returns the cosine of an angle (in radians).
Example:
The following example returns the COSINE angle of 60 radians.

Select  cos(60) “Cosine” from dual;

SIN
Returns the Sine of an angle (in radians).
Example:
The following example returns the SINE angle of 60 radians.
select  SIN(60) “Sine” from dual;

TAN
Returns the Tangent of an angle (in radians).
Example:
The following example returns the tangent angle of 60 radians.

Select  Tan(60) “Tangent” from dual;

Similar to SIN, COS, TAN  functions hyperbolic functions  SINH, COSH, TANH are also available in oracle.

MOD
Returns the remainder after dividing m with n.
Example
The following example returns the remainder after dividing 30 by 4.

Select mod(30,4) “MOD” from dual;

Output:
MOD
---------
        2
POWER
Returns the power of m, raised to n.
Example
The following example returns the 2 raised to the power of 3.

Select  power(2,3) “Power” from dual;

Output:
POWER
---------
        8

EXP
Returns the e raised to the power of n.
Example
The following example returns the e raised to power of 2.

Select exp(2) “e raised to 2” from dual;

Output:
E RAISED TO 2
-------------
       
LN
Returns natural logarithm of n.
Example
The following example returns the natural logarithm of 2.

Select ln(2) from dual;

Output:
LN
------------

LOG
Returns the logarithm, base m, of n.

Example
The following example returns the log of 100.

Select log(10,100) from dual;

Ouput:
LOG
---------
        2

ROUND
Returns a decimal number rounded of to a given decimal positions.
Example
The following example returns the no. 3.4573 rounded to 2 decimals.

Select round(3.4573,2) “Round” from dual;

Ouput:
Round
------------
        3.46

TRUNC 
Returns a decimal number Truncated to a given decimal positions.
Example
The following example returns the no. 3.4573 truncated to 2 decimals.

Select Trunc(3.4573,2) “Round” from dual;

Output:
Trunc
------------
        3.45

SQRT
Returns  the square root of a given number.
Example
The following example returns the square root of  16.

Select  sqrt(16) from dual;

Ouput:
SQRT
---------
        4