<<<<<<< HEAD power | H2 | SQLDoc
Skip to main content

power

1. POWER Function

======= power | H2 Function | SQLDoc

power

1. POWER Function

>>>>>>> 9d19b1c8cb744c8e86d5c15b74d8b5f719ad62be

The POWER function in H2 database is used to raise a number to a specified power.

2. Syntax

The syntax for the POWER function in H2 database is as follows:

POWER(base, exponent)

Arguments

  • base: The base number that needs to be raised to the power.
  • exponent: The exponent to which the base number should be raised.

Return

  • The POWER function returns the value of the base raised to the power of the exponent.

3. Notes

  • Both the base and exponent arguments in the POWER function should be numeric values.
  • If either the base or the exponent is NULL, the result will be NULL.
  • The result of the POWER function is a DOUBLE value.
  • Take care to avoid any potential division by zero errors when using the POWER function.

4. Examples

Here are a few examples demonstrating the usage of the POWER function in H2 database:

Example 1 - Calculating the power of a number:

SELECT POWER(2, 3) AS result;

Output:

result
------
8.0

Example 2 - Calculating the power using column values:

CREATE TABLE numbers (
id INT PRIMARY KEY,
base DOUBLE,
exponent INT
);

INSERT INTO numbers VALUES (1, 2.5, 2), (2, 10, 3), (3, 1.5, 4);

SELECT id, base, exponent, POWER(base, exponent) AS result
FROM numbers;

Output:

id | base | exponent |  result
---+------+----------+----------
1 | 2.5 | 2 | 6.25
2 | 10 | 3 | 1000.0
3 | 1.5 | 4 | 5.0625
  • sqrt - Calculate square root
  • exp - Calculate exponential value