SQL Tutorial SQL Advanced SQL Database SQL References

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:

Datax
Data 10.5
Data 21
Data 35
Data 410
Data 550

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:

DataxLOG_Value
Data 10.5-.3010299956639811952137388947244930267692
Data 210
Data 35.6989700043360188047862611052755069732341
Data 4101
Data 5501.69897000433601880478626110527550697323

Example 3:

Consider a database table called Sample with the following records:

Dataxy
Data 10.52
Data 224
Data 3510
Data 41010
Data 55010

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:

DataxyLOG_Value
Data 10.52-1
Data 2241.99999999999999999999999999999999999998
Data 35101.43067655807339305067010656876396563207
Data 410101
Data 55010.5885919100677789540727891692371378520662

❮ Oracle Functions