Name
POWER
Synopsis
Use POWER to raise a number to a specific value.
SQL2003 Syntax
POWER(base
,exponent
)
The result of the POWER function is
base
raised to the
exponent
power, or
baseexponent
. If
base
is negative, then
exponent
must be an integer.
DB2, Oracle, PostgreSQL, and SQL Server
These vendors all support the SQL2003 syntax.
MySql
MySQL supports the same functionality, but requires the use of the keyword POW:
POW(base
,exponent
)
Example
Raising a positive number to an exponent is straightforward:
SELECT POWER(10,3) FROM dual;
POWER(10,3)
-----------
1000
Anything raised to the 0th power evaluates to 1:
SELECT POWER(0,0) FROM dual;
POWER(0,0)
----------
1
Negative exponents move the decimal point to the left:
SELECT POWER(10,-3) FROM dual;
POWER(10,-3)
------------
.001
Get SQL in a Nutshell, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.