Oracle BITAND() Function

Oracle BITAND() is a built-in function that returns the result of a bitwise AND operation of two parameters.

Oracle BITAND() syntax

Here is the syntax for the Oracle BITAND() function:

BITAND(expr1, expr2)

Parameters

expr1

Required.

expr2

Required.

expr1 and expr2 are of NUMBER type and they must be in the range -(2(n-1)) .. ((2(n-1))-1).

Return Value

The Oracle BITAND() function returns the result of the bitwise AND operation of two parameters. It is of NUMBER type.

If any parameter is NULL, BITAND() will return NULL.

Oracle BITAND() Examples

Here are some examples that demonstrate the usage of the Oracle BITAND() function.

Basic Usage

SELECT
    BITAND(5, 3)
FROM dual;

Output:

   BITAND(5,3)
______________
             1

The operation process of this function is as follows:

    5 -> 101
    3 -> 011
AND --------
         001

NULL Parameters

If any parameter is NULL, BITAND() will return NULL.

SET NULL 'NULL';
SELECT
    BITAND(1, NULL),
    BITAND(NULL, 1),
    BITAND(NULL, NULL)
FROM dual;

Output:

   BITAND(1,NULL)    BITAND(NULL,1)    BITAND(NULL,NULL)
_________________ _________________ ____________________
             NULL              NULL                 NULL

In this example, we use the statement SET NULL 'NULL'; to display NULL values as the string 'NULL'.

Conclusion

Oracle BITAND() is a built-in function that returns the result of a bitwise AND operation of two parameters.