Oracle POWER() Function
The Oracle (PL/SQL) POWER() function returns the base raise to the power of exponent. In special cases it returns the following:
- If the exponent is zero, then 1 is returned.
Note: If base is negative, then exponent must be an integer.
Syntax
POWER(base, exponent)
Parameters
base |
Required. Specify the base of type float or of a type that can be implicitly converted to float. |
exponent |
Required. Specify the exponent. |
Return Value
Returns the base raise to the power of exponent.
Example 1:
The example below shows the usage of POWER() function.
POWER(5, 2) Result: 25 POWER(3, 5) Result: 243 POWER(5.5, 2) Result: 30.25 POWER(5.5, 2.1) Result: 35.87250030349097934823304189170854145697 POWER(5, -1) Result: .2 POWER(5, 0) Result: 1 POWER(0, 5) Result: 0
Example 2:
Consider a database table called Sample with the following records:
Data | x |
---|---|
Data 1 | 0.5 |
Data 2 | 1 |
Data 3 | 5 |
Data 4 | 10 |
Data 5 | 50 |
The statement given below can be used to calculate the square root of column x.
SELECT Sample.*, POWER(x, 0.5) AS POWER_Value FROM Sample;
This will produce the result as shown below:
Data | x | POWER_Value |
---|---|---|
Data 1 | 0.5 | .7071067811865475244008443621048490392667 |
Data 2 | 1 | 1 |
Data 3 | 5 | 2.23606797749978969640917366873127623544 |
Data 4 | 10 | 3.16227766016837933199889354443271853374 |
Data 5 | 50 | 7.07106781186547524400844362104849039283 |
Example 3:
Consider a database table called Sample with the following records:
Data | x | y |
---|---|---|
Data 1 | 0.5 | 2 |
Data 2 | 1 | 3 |
Data 3 | 5 | 4 |
Data 4 | 10 | 3 |
Data 5 | 50 | 3 |
To calculate the records of column x raised to the power of records of column y, the following query can be used:
SELECT Sample.*, POWER(x, y) AS POWER_Value FROM Sample;
This will produce the result as shown below:
Data | x | y | POWER_Value |
---|---|---|---|
Data 1 | 0.5 | 2 | 0.25 |
Data 2 | 1 | 3 | 1 |
Data 3 | 5 | 4 | 625 |
Data 4 | 10 | 3 | 1000 |
Data 5 | 50 | 3 | 125000 |
❮ Oracle Functions