Skip to main content

# POWER

A numeric function that returns the value of a given expression raised to the specified power.

## Synopsis

```POWER(numeric-expression,power)

{fn POWER(numeric-expression,power)}
```

### Arguments

Argument Description
numeric-expression The base number. Can be a positive or negative integer or fractional number.
power The exponent, which is the power to which to raise numeric-expression. Can be a positive or negative integer or fractional number.

POWER returns either the NUMERIC or DOUBLE data type. If numeric-expression is data type DOUBLE, POWER returns DOUBLE; otherwise, it returns NUMERIC.

## Description

POWER calculates one number raised to the power of another. It returns a value with a precision of 36 and a scale of 18.

Note that POWER can be invoked as an ODBC scalar function (with the curly brace syntax) or as an SQL general scalar function.

POWER interprets a non-numeric string as 0 for either argument. For further details, refer to Strings as Numbers. POWER returns NULL if passed a NULL value for either argument.

All combinations of numeric-expression and power are valid except:

• POWER(0,-m): a 0 numeric-expression and a negative power results in an SQLCODE -400 error.

• POWER(-n,.m): a negative numeric-expression and a fractional power results in an SQLCODE -400 error.

## Examples

The following example raises 5 to the 3rd power:

`SELECT POWER(5,3) AS Cubed`

returns 125.

The following embedded SQL example returns the first 16 powers of 2:

```   SET a=1
WHILE a<17 {
&sql(SELECT {fn POWER(2,:a)}
INTO :b)
IF SQLCODE'=0 {
WRITE !,"Error code ",SQLCODE
QUIT }
ELSE {
WRITE !,"2 to the ",a," = ",b
SET a=a+1 }
}```

## See Also

FeedbackOpens in a new window