In Oracle, the EXP()
function returns the value of e (the base of natural logarithms) raised to the power of the argument.
The number e, also known as Euler’s number, is a mathematical constant approximately equal to 2.71828.
Syntax
The syntax goes like this:
EXP(n)
Where n
is any numeric data type or any nonnumeric data type that can be implicitly converted to a numeric data type.
Example
Here’s an example:
SELECT EXP(5)
FROM DUAL;
Result:
EXP(5) ___________________________________________ 148.413159102576603421115580040552279624
We can get the value of e by passing 1:
SELECT EXP(1)
FROM DUAL;
Result:
EXP(1) ___________________________________________ 2.71828182845904523536028747135266249776
Fractions
The argument can contain a fractional part:
SELECT EXP(3.1434178)
FROM DUAL;
Result:
EXP(3.1434178) ____________________________________________ 23.18296635099516749674346410871112767972
Negative Values
The argument can be negative:
SELECT EXP(-5)
FROM DUAL;
Result:
EXP(-5) _______________________________________________ 0.006737946999085467096636048423148424248801
Expressions
The argument can include expressions like this:
SELECT EXP(2 * 3)
FROM DUAL;
Result:
EXP(2*3) ___________________________________________ 403.428793492735122608387180543388279609
Non-Numeric Arguments
The argument can be any numeric data type or any nonnumeric data type that can be implicitly converted to a numeric data type.
Here’s an example of what happens when the argument doesn’t satisfy that criteria:
SELECT EXP('Cat')
FROM DUAL;
Result:
Error starting at line : 1 in command - SELECT EXP('Cat') FROM DUAL Error report - ORA-01722: invalid number
Null Arguments
EXP()
returns null
if the argument is null
:
SET NULL 'null';
SELECT EXP(null)
FROM DUAL;
Result:
EXP(NULL) ____________ null
By default, SQLcl and SQL*Plus return a blank space whenever a null value occurs as a result of a SQL SELECT
statement.
However, you can use SET NULL
to specify a different string to be returned. Here I specified that the string null
should be returned.
Missing Arguments
Calling EXP()
with the wrong number of arguments, or without any arguments results in an error:
SELECT EXP()
FROM DUAL;
Result:
Error starting at line : 1 in command - SELECT EXP() FROM DUAL Error at Command Line : 1 Column : 8 Error report - SQL Error: ORA-00909: invalid number of arguments 00909. 00000 - "invalid number of arguments" *Cause: *Action:
And:
SELECT EXP(10, 2)
FROM DUAL;
Result:
Error starting at line : 1 in command - SELECT EXP(10, 2) FROM DUAL Error at Command Line : 1 Column : 8 Error report - SQL Error: ORA-00909: invalid number of arguments 00909. 00000 - "invalid number of arguments" *Cause: *Action: