If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > need help logarithm function

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-24-04, 10:59
ronenshi ronenshi is offline
Registered User
 
Join Date: Sep 2004
Posts: 33
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
Reply With Quote
  #2 (permalink)  
Old 10-25-04, 04:03
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
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.
Reply With Quote
  #3 (permalink)  
Old 10-25-04, 10:51
ronenshi ronenshi is offline
Registered User
 
Join Date: Sep 2004
Posts: 33
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)@
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On