Oracle POWER Function: A Simple Guide

The POWER function in Oracle SQL is a straightforward mathematical function that raises one number to the power of another number.

This is the standard function to use when you need to perform exponentiation, such as squaring a number, cubing a number, or even calculating roots.

What is the POWER Function in Oracle?

The POWER(n2, n1) function answers the question: "What is n2 raised to the power of n1?" (or n2^n1).

  • n2 (the base): The number that will be multiplied by itself.
  • n1 (the exponent): The number of times to multiply the base.
  • POWER(3, 2) returns 9 (because 3 * 3 = 9).
  • POWER(2, 3) returns 8 (because 2 * 2 * 2 = 8).

POWER Function Syntax

The syntax for POWER requires two arguments:

POWER(n2, n1)

Let's break that down:

  • n2 (the base): The number you are starting with.
  • n1 (the exponent): The power you want to raise the base to.

Note: If the base (n2) is negative, the exponent (n1) must be an integer.

Oracle POWER Function Examples

Here are two practical examples of how to use POWER.

Example 1: Squaring a Number

This example calculates 5 raised to the power of 2 (5 squared).

Query:

SELECT 
  POWER(5, 2) AS "5_Squared"
FROM DUAL;

Result:

 5_Squared
----------
        25

Example 2: Calculating a Square Root

You can also use POWER to find roots by using a fractional exponent. Raising a number to the power of 0.5 is the same as finding its square root.

Query:

SELECT 
  POWER(81, 0.5) AS "Square_Root_of_81"
FROM DUAL;

Result:

Square_Root_of_81
-----------------
                9
Get more Vinish.dev tutorials on Google

See my articles more often when you search Google.

Vinish Kapoor
Vinish Kapoor

An Oracle ACE, author of four books on Oracle APEX, SQL and PL/SQL, and Oracle Forms, and a software developer building Oracle database applications since 2001.

guest

0 Comments
Oldest
Newest Most Voted