Bitwise OR in Oracle

This is another one of those "for my own reference" posts, because I have virtually no experience with Oracle and I'll likely forget about this in a couple of months. 

Here's a handy link on creating a bitwise OR function in Oracle.  There's a built-in BITAND function that does a bitwise AND, but no corresponding OR.  Fortunately, it turns out that you can do an OR in terms of AND using the following:

function bitor(p_dec1 number, p_dec2 number) return number is
  return p_dec1-bitand(p_dec1,p_dec2)+p_dec2;

In my case, I actually just needed the formula, not the actual function, as it was for a one-off data migration query.  However, I did have an extra wrinkle in that I needed to do the bitwise OR on a CLOB column.  But that turned out to not be a big deal either, as simply running the column through the TO_NUMBER() function was all I needed.  So it actually worked out pretty well.

You can reply to this entry by leaving a comment below. You can send TrackBack pings to this URL. This entry accepts Pingbacks from other blogs. You can follow comments on this entry by subscribing to the RSS feed.

Add your comments #

A comment body is required. No HTML code allowed. URLs starting with http:// or ftp:// will be automatically converted to hyperlinks.