Caché SQL Reference
POWER
[Home] [Back] [Next]
InterSystems: The power behind what matters   
Class Reference   
Search:    

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
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.
Description
POWER calculates one number raised to the power of another. It returns a value of data type DECIMAL 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:
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