docs.intersystems.com
Home  /  Application Development: Core Topics  /  InterSystems SQL Reference  /  SQL Functions  /  POWER


InterSystems SQL Reference
POWER
[Back]  [Next] 
InterSystems: The power behind what matters   
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.
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:
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