POWER
POWER is an SQL function that returns the value of a number raised to the power of another number.
POWER(base, exponent)
- base: The number that serves as the base in the exponentiation calculation. It can be any valid numeric type and must be provided in order to use the POWER function.
- exponent: The number that serves as the exponent in the calculation. It indicates the number of times the ‘base’ value is multiplied by itself. This also can be any valid numeric type and must be supplied as a parameter in the POWER function.
Example
Output
Explanation
In the given example, the POWER() function in MySQL takes two arguments. The first argument is the base, while the second argument is the exponent. The function returns the base raised to the power of the exponent. So, POWER(2,3) would compute 2 to the power of 3, resulting in 8.
POWER( float_expression , y )
- float_expression: the base number which is a valid float expression. It is the number to which the exponentiation operation is performed.
- y: the exponent and also a valid float expression. It is the number by which the base number is to be raised.
Example
Output
Explanation
In the example, the SQL Server POWER()
function has been used to calculate the power of the number. The use of POWER(3, 4)
means 3 raised to the power of 4. The computation resulted to 27.
POWER(N1, N2)
- n1: This represents the base number that will be raised to the power of N2. Must be a numeric value.
- n2: This denotes the exponent to which the base number (N1) will be raised. Must also be a numeric value.
Example
Output
Explanation
The POWER() function is used in the SELECT statement to raise the base number (first argument: 4) to the power of the exponent (second argument: 2). The function returns the result of this operation, here, 16.
POWER(base FLOAT8, exponent FLOAT8) RETURNS FLOAT8
- base float8: This is a floating-point number that serves as the base for the power operation. It can handle positive, negative, and zero values. It also works with decimal numbers.
- exponent float8: This is a floating-point number that serves as the exponent in the power operation. Similarly to the base, it can handle positive, negative, and zero values including decimals. It determines the power to which the base is to be raised.
Example
Output
Explanation
The POWER function in PostgreSQL is used to raise the first number (base value) to the power of the second number (exponent value). In this case, it raises 2 to the power of 3, which results in 8.