BITAND function in Oracle with Real Examples

In previous articles i have given the idea about the different types of functions in Oracle. In this article i would like to discuss the special function which user needs to use. These kind of functions are mostly used in warehouse operation business logic in most of the cases.In this article i would like to give you heads-up about the bitwise operators concept and then BITAND function with real life industry examples.

What is BITWISE AND functionality?

Initially i need to explain the BITWISE AND functionality with one or two examples. The output of bitwise AND is 1 if the corresponding bits of two operands is one. If any of the bit is 0 then the result will be evaluated as 0.In electronics the bitwise and operator functionality is very important.

Simple Example of BITWISE AND :

I would like to go through one example so that the concept of Bitwise And will get cleared :

12  Need to convert to Binary . Binary 12= 00001100 
25  Need to convert to Binary . Binary 25= 00011001 

Bit Operation of 12 and 25
  00001100
& 00011001
  ________
  00001000  = 8 (In decimal)

The result of 12 and 25 = 8 .

BITAND function in Oracle with real examples :

SQL Programming Examples

In this section i would like to explain the BITAND function in oracle with real life industry examples. The BITAND function works same like BITWISE AND operator. The return value is always the BITWISE AND of two numbers.The return value is always the Integer number.

Syntax :

BITAND( Number1,Number2);

Kindly check the following bullet points related to BITAND operator ,

1.The range of arguments in BITAND function will be -(2(n-1)) .. ((2(n-1))-1 .

2.If the argument of BITAND function is NULL the result will be always NULL.

3.BITAND always returns a decimal number.

4.If either argument is less than 0, BITAND function always returns error.

5. If either argument is a non-integer or is greater than (2^48)-1, BITAND returns the error.

6.If either value is non numeric BITAND returns ERROR.

7. If user can use float then it will round the two numbers and present result.

Real Life Industry Examples :

If there is requirement where user needs the Bitwise AND result of some columns then following queries are useful,

Query 1 :

Select BITAND(1,5) from Dual;

Result :

1

Example :

The binary representation of 1 is 1, and the binary representation of 5 is 101. Their bits match only at the rightmost position. This is returned as 2^0, or 1.

Query 2 :

Select BITAND(15,7) from dual;

Result :

7

The main purpose of this BITAND function is to do the operation of bitwise AND operator. Hope you like this article. If you like this article or if you have any concerns with the same kindly comment in comments section.

Leave a Reply

Your email address will not be published. Required fields are marked *