Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2004
    Posts
    35

    Unanswered: need help logarithm function

    Hi,
    Im converting an oracle sql statement to db2 and we use the oracle's log function with the base 2 as an argument , in db2 the log function uses the base log or 10 as argument . my question is how can i use the base 2 (or pass the base as argument) in db2?
    10x

  2. #2
    Join Date
    Aug 2001
    Location
    UK
    Posts
    4,650
    In general

    log a (base x) = log a (base z)/ log x (base z)

    Applying this to convert log base 2 to base 10

    log a (base 2) = 3.32 x log a (base 10)

    HTH

    Sathyaram
    Visit the new-look IDUG Website , register to gain access to the excellent content.

  3. #3
    Join Date
    Sep 2004
    Posts
    35
    10x a lot
    i used this
    CREATE FUNCTION LOG2(value float)
    returns float
    LANGUAGE SQL
    DETERMINISTIC
    NO EXTERNAL ACTION
    CONTAINS SQL
    return ln(value)/ln(2)@

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •