SQLite power() Function

Summary: in this tutorial, you will learn how to use the SQLite power() function to raise a number to a specific power.

Introduction to SQLite power() function

The power() function allows you to raise a number to a specific power.

Here’s the syntax of the power() function:

power(base, exponent)Code language: SQL (Structured Query Language) (sql)

In this syntax:

  • base: is the base number.
  • exponent: is the exponent you want to raise the base number.

The power() function returns the base raised to the power exponent. It returns NULL if either base or exponent is NULL.

Please note that the power() and pow() function are synonyms, therefore, you can use them interchangeably.

SQLite power() function examples

Let’s explore some examples of using the power() function.

1) Basic power() function examples

The following statement uses the power() function to raise the number 2 to the power of 3:

SELECT power(2,3) result;Code language: SQL (Structured Query Language) (sql)

Output:

result
------
8.0Code language: SQL (Structured Query Language) (sql)

Likewise, you can use the power() function with decimal numbers:

SELECT power(2.5, 3) result;Code language: SQL (Structured Query Language) (sql)

Output:

result
------
15.625Code language: SQL (Structured Query Language) (sql)

2) Using the power() function with decimal exponents

The following example uses the power() function to raise the number 1.5 to the power of 2.5:

SELECT power(1.5, 2.5) result;Code language: SQL (Structured Query Language) (sql)

Output:

result
------------------
2.7556759606310752Code language: SQL (Structured Query Language) (sql)

Please note that the return value is approximate, but not accurate.

Summary

  • Use the power() function to raise a number to a specific power.
Was this tutorial helpful ?