Categories: SQL Complex Queries

What is BITAND function in Oracle with 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 :

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.

Amit S

Oracle Consultant with vast experience in Oracle BI and PL/SQL Development. Amiet is the admin head of this website who contributes by preparing tutorials and articles related to database technologies. He is responsible to manage the content and front-end of the website.

Share
Published by
Amit S

Recent Posts

What is Root Cause Analysis (RCA) With real examples

In my previous article I have given details about application support engineer day to day…

2 days ago

Application Support Engineer Day to day responsibilities

In my previous articles I have given the roles and responsibilities of L1,L2 and L3…

4 days ago

What is mean by SLA ( Service Level Agreement) with Examples?

In my previous articles i have given the hierarchy of production support in real company…

7 days ago

What is Production support Hierarchy in organization?

In this article i would like to provide information about production support organization structure or…

7 days ago

What are roles and responsibilities for L3 Support Engineer?

In my previous article I have given roles for L1 and L2 support engineer with…

7 days ago

What are roles and responsibilities of L2 Engineer?

I have started this new series of how to become application support engineer. This article…

7 days ago