Oracle LOG() Function
The Oracle (PL/SQL) LOG() function returns the logarithm to the specified base of a given number. In special cases it returns the following:
- If the number is less than or equal to 0, then an error is returned.
- If the base is less than or equal to 0, then an error is returned.
- If the base is equal to 1, then an error is returned.
Syntax
LOG(base, number)
Parameters
base |
Required. Specify the number. Must be greater than 0 and not equal to 1. |
number |
Required. Specify the number. Must be greater than 0. |
Return Value
Returns the logarithm to the specified base of a given number.
Example 1:
The example below shows the usage of LOG() function.
LOG(4, 3) Result: .792481250360578090726869471973908254388 LOG(0.8, 0.7) Result: 1.59841026925531125295926382550462121511 LOG(10, 0.5) Result: -.3010299956639811952137388947244930267692 LOG(5, 25) Result: 1.99999999999999999999999999999999999999
Example 2:
Consider a database table called Sample with the following records:
Data | x |
---|---|
Data 1 | 0.5 |
Data 2 | 1 |
Data 3 | 5 |
Data 4 | 10 |
Data 5 | 50 |
The statement given below can be used to calculate the base-10 logarithm of values of column x.
SELECT Sample.*, LOG(10, x) AS LOG_Value FROM Sample;
This will produce the result as shown below:
Data | x | LOG_Value |
---|---|---|
Data 1 | 0.5 | -.3010299956639811952137388947244930267692 |
Data 2 | 1 | 0 |
Data 3 | 5 | .6989700043360188047862611052755069732341 |
Data 4 | 10 | 1 |
Data 5 | 50 | 1.69897000433601880478626110527550697323 |
Example 3:
Consider a database table called Sample with the following records:
Data | x | y |
---|---|---|
Data 1 | 0.5 | 2 |
Data 2 | 2 | 4 |
Data 3 | 5 | 10 |
Data 4 | 10 | 10 |
Data 5 | 50 | 10 |
To calculate the logarithm of records of column y with base as records of column x, the following query can be used:
SELECT Sample.*, LOG(x, y) AS LOG_Value FROM Sample;
This will produce the result as shown below:
Data | x | y | LOG_Value |
---|---|---|---|
Data 1 | 0.5 | 2 | -1 |
Data 2 | 2 | 4 | 1.99999999999999999999999999999999999998 |
Data 3 | 5 | 10 | 1.43067655807339305067010656876396563207 |
Data 4 | 10 | 10 | 1 |
Data 5 | 50 | 10 | .5885919100677789540727891692371378520662 |
❮ Oracle Functions