Numeric Functions

PL/SQL implements a number of functions that are useful when working with numbers. We list those functions in Table 9-6, and describe each of them in detail in the sections that follow.

Table 9-6. PL/SQL's built-in numeric functions
Name Description
ABS Returns the absolute value of a number.
ACOS Returns the inverse cosine.
ASIN Returns the inverse sine.
ATAN Returns the inverse tangent.
ATAN2 Returns the inverse tangent of a value, but allows you to pass that value differently than when using ATAN.
BITAND Performs an AND operation on the bits from two positive integer numbers.
CEIL Returns the smallest integer greater than or equal to the specified number.
COS Returns the cosine.
COSH Returns the hyperbolic cosine.
EXP (n) Returns the number e raised to the nth power, where e = 2.71828183...
FLOOR Returns the largest integer equal to or less than the specified number.
LN (a) Returns the natural logarithm of a.
LOG (a, b) Returns the logarithm, base a, of b.
MOD (a, b) Returns the remainder of a divided by b.
POWER (a, b) Returns a raised to the bth power.
ROUND (a, [b]) Returns a rounded to b decimal places.
SIGN (a) Returns 1 if a is positive, 0 if a is 0, and -1 if a is less than 0 (i.e., negative).
SIN Returns the sine.
SINH Returns the hyperbolic sine.
SQRT Returns the square root of a number.
TAN Returns the tangent.
TANH Returns the hyperbolic tangent.
TRUNC (a, [b]) Returns a truncated to b decimal places.

Note that the trigonometric and logarithmic functions are available only in PL/SQL Version 2.0 and subsequent releases. The inverse trigonometric functions are available only in PL/SQL Release 2.3 and higher.

When using the trigonometric functions, be aware that all angles are expressed in radians, not in degrees. You can convert between radians and degrees as follows:

radians = * degrees / 180 -- From degrees to radians

degrees = radians * 180 / -- From radians to degrees

Oracle Corporation did not implement a function for (pi) itself. However, you can obtain the value for through the following call:

ACOS (-1)

The inverse cosine (ACOS) of -1 happens to be defined as exactly . Of course, because is a never-ending decimal number, you always have to work with an approximation. Use the ROUND function if you wish to round the results of ACOS(-1) to a specific number of decimal places.

We'll look quickly at the rounding and truncation functions, and then provide summaries of each of PL/SQL's built-in numeric functions. For each, we'll include the specification, some examples, and a brief description.