In Oracle, the BITAND() function returns a bitwise AND of its two arguments.
Syntax
The syntax goes like this:
BITAND(expr1, expr2)
Where expr1 and expr2 are of type NUMBER.
The arguments must be in the range -(2(n-1)) .. ((2(n-1))-1). If an argument is out of this range, the result is undefined.
Also, if either argument is NULL, the result is NULL.
Example
Here’s an example:
SELECT BITAND(6, 3)
FROM DUAL;
Result:
BITAND(6,3)
______________
2
Non-Numeric Arguments
Here’s what happens when we provide a non-numeric argument that can’t be converted to a numeric data type:
SELECT BITAND('six', 3)
FROM DUAL;
Result:
Error starting at line : 1 in command -
SELECT BITAND('six',3)
FROM DUAL
Error report -
ORA-01722: invalid number
Null Values
If any of the arguments are null, the result is null:
SET NULL 'null';
SELECT
BITAND(null, 3),
BITAND(6, null)
FROM DUAL;
Result:
BITAND(NULL,3) BITAND(6,NULL)
_________________ _________________
null null
By default, SQLcl and SQL*Plus return a blank space whenever null occurs as a result of a SQL SELECT statement.
However, you can use SET NULL to specify a different string to be returned. Here I specified that the string null should be returned.
Incorrect Argument Count
Calling BITAND() without passing any arguments returns an error:
SELECT BITAND()
FROM DUAL;
Result:
Error starting at line : 1 in command - SELECT BITAND() FROM DUAL Error at Command Line : 1 Column : 8 Error report - SQL Error: ORA-00909: invalid number of arguments 00909. 00000 - "invalid number of arguments" *Cause: *Action:
And passing the wrong number of arguments results in an error:
SELECT BITAND(1, 2, 3)
FROM DUAL;
Result:
Error starting at line : 1 in command - SELECT BITAND(1, 2, 3) FROM DUAL Error at Command Line : 1 Column : 8 Error report - SQL Error: ORA-00909: invalid number of arguments 00909. 00000 - "invalid number of arguments" *Cause: *Action: