MySQL POW() Function
MySQL POW() Function: Raising Numbers to Any Power
The POW() function returns the value of a base number x raised to the power of an exponent y. It is a direct synonym for POWER() in MySQL and always returns a DOUBLE floating-point result.
Beyond squaring or cubing dimensions, POW() handles negative exponents (POW(10, -2) = 0.01) and fractional exponents for roots (POW(27, 1/3) = 3). It is essential for compound interest and exponential growth formulas.
Syntax
POW(x, y)
x: Base numeric expression.y: Exponent numeric expression.
Practical Example
Suppose demo_orders tracks installment financing plans with principal, annual_rate, and years. You can compute the compounded balance using principal * POW(1 + annual_rate, years).
SELECT
order_id,
principal,
annual_rate,
years,
ROUND(principal * POW(1 + annual_rate, years), 2) AS total_payable
FROM demo_orders
WHERE principal IS NOT NULL;
| order_id | principal | annual_rate | years | total_payable |
|---|---|---|---|---|
| 651 | 1000.00 | 0.05 | 3 | 1157.63 |
| 652 | 2500.00 | 0.08 | 2 | 2916.00 |
| 653 | 1200.00 | 0.06 | 0 | 1200.00 |
On order 653, POW(1.06, 0) evaluates to 1, leaving the principal unchanged at 1200.00.
Common Mistakes & NULL Behavior
- Using the ^ operator for exponents: In MySQL,
2 ^ 3does NOT mean2cubed! The caret^is a bitwiseXORoperator (2 ^ 3returns1). Always writePOW(2, 3)orPOWER(2, 3)for exponentiation. - Overflowing DOUBLE range: Huge powers like
POW(10, 400)exceed IEEE 754DOUBLEcapacity and raiseERROR 1690 (22003): DOUBLE value is out of range. - Negative base with fractional exponent: Raising a negative number to a non-integer exponent (such as
POW(-4, 0.5)) has no real solution and causes an error orNULLdepending on platform math handling. Validatex >= 0before taking fractional roots. - NULL propagation: If either
xoryisNULL,POW(x, y)returnsNULL.
Frequently Asked Questions
What does POW(0, 0) return in MySQL?
MySQL defines POW(0, 0) as 1. However, POW(0, -1) raises an out-of-range division-by-zero error.
Is POW() different from POWER() in MySQL?
No. POW() and POWER() are exact aliases in MySQL and produce identical output.
Unlock Your
Full Potential.
Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.
Quick Access With
Try it Yourself
Experiment with the code from this lesson in our interactive playground.