w3resource

SQL EXP() function

EXP() function

SQL EXP() function returns e raised to the n-th power(n is the numeric expression), where e is the base of a natural algorithm and the value of e is approximately 2.71828183.

Syntax:

 EXP(expression) 

Parameters:

Name Description
expression An expression which is a float or can be converted to a float.

MySQL, PostgreSQL, SQL Server, and Oracle

All of above platforms support the SQL syntax of EXP().

SQL EXP() function: Visual presentation

SQL EXP() function

Example:

To get the e raised by 2's power from the DUAL table, the following SQL statement can be used:


-- This SQL statement calculates the value of the constant 'e' raised to the power of 2 and renames the result as 'e_to_2s_power', selecting the result from the 'dual' table.
SELECT EXP(2) AS e_to_2s_power 
-- SELECT statement retrieves data from the database
-- EXP() function calculates the value of the constant 'e' raised to the power of the specified number
-- In this case, EXP(2) calculates 'e' raised to the power of 2
FROM dual;
-- Specifies the 'dual' table, a special one-row, one-column table present in Oracle database
-- The 'dual' table is often used for performing calculations or returning single results in SQL queries

Explanation:

  • This SQL query is straightforward, as it's only a single statement.
  • The purpose of this query is to calculate the value of the constant 'e' raised to the power of 2.
  • EXP() is a mathematical function that calculates the exponential value of 'e' raised to the power of the specified number.
  • In this case, EXP(2) will return the value of 'e' raised to the power of 2, which is approximately 7.389056.
  • The AS keyword is used to rename the result of the calculation as 'e_to_2s_power' for easier identification in the query result.
  • The 'dual' table is used here because it's a convenient way to execute single-row queries in Oracle SQL without needing to specify an actual table with data.

Output:

E_TO_2S_POWER
-------------
    7.3890561

Note: Outputs of the said SQL statement shown here is taken by using Oracle Database 10g Express Edition.

Here is a slide presentation which covers the SQL arithmetic functions.

Check out our 1000+ SQL Exercises with solution and explanation to improve your skills.

Previous: FLOOR
Next: LN



Follow us on Facebook and Twitter for latest update.