Thursday, November 6, 2008

Oracle: Binary operations

Today i faced a situation when i need to do binary operations in Oracle Query. I had no idea how to do it. Obviously Googling worked as always. :-) :-) . Below was the problem:

I need to apply AND operation on a hexadecimal number as below but following query did not work.

select <num> & 0xf from dual;

I found that BITAND function will do this task, so i chnaged above query to as below and it worked.

select BITAND(<num>, 15)+0 from dual;
(here 15 is equivalent to 0xf, Note that BITAND returns a binary integer, so to use it in SQL you will need to convert it to a numeric.)

Similarly, Oracle has BITOR function for OR operation.

AARTI: Shree Google Maharaaj :-)

Recently i got an email from one of my friends which had Aarti for Google. Though it is in Hindi but i thought it to share with you all. If you know Hindi, then just read it and enjoy .. :) :)