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
Vinish Kapoor
Vinish Kapoor

Vinish Kapoor is a seasoned software development professional and a fervent enthusiast of artificial intelligence (AI). His impressive career spans over 25+ years, marked by a relentless pursuit of innovation and excellence in the field of information technology. As an Oracle ACE, Vinish has distinguished himself as a leading expert in Oracle technologies, a title awarded to individuals who have demonstrated their deep commitment, leadership, and expertise in the Oracle community.

guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments