Home / InterSystems SQL Reference / SQL Functions / POWER

InterSystems SQL Reference
Previous section           Next section
InterSystems: The power behind what matters   

A numeric function that returns the value of a given expression raised to the specified power.
{fn POWER(numeric-expression,power)}
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.
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:
The following example raises 5 to the 3rd power:
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

Previous section           Next section
Send us comments on this page
View this book as PDF   |  Download all PDFs
Copyright © 1997-2019 InterSystems Corporation, Cambridge, MA
Content Date/Time: 2019-07-17 06:47:31