Quick Search:
Oracle PL/SQL Code Library
Find Or Post Oracle Jobs
Oracle Discussion & Chat
 The Oracle BITAND Function      [Return To Index] Jump to:  
  Looking for the original pages? (formerly called "Morgan's Library") You can find them here.


The BITAND function is used to determine whether a particular bit is set or not. It is most commonly used with the DECODE function. The function takes 2 arguments and performs these steps:

  • Converts the 2 arguments to binary (n-bit two's complement binary integer value)
  • Performs a standard bitwise AND operation on the two strings
  • Converts the binary result back to a decimal format
The BITAND function essentially does a logical AND of two bit strings. If the values in any position are both '1', then the result will have a '1' in that position, otherwise the result will have a '0' in that position. This is a very fast, very efficient way of checking if a particular bit has been set. It's efficient because it makes use of a technique called 'bit masking'.

Example Syntax:

bitand( expr1, expr2 )

BITAND computes an AND operation on the bits of expr1 and expr2, both of which must resolve to non-negative integers. BITAND returns an integer value.

NOTE: The BITAND function does not determine the datatype of the value returned. Therefore, in SQL*Plus, you must specify BITAND in a wrapper, such as TO_NUMBER, which returns a datatype.

Related Links:
Home      :      Code Library      :      Sponsors      :      Privacy      :      Terms of Use      :      Contact Us 24 users online    © 2009 psoug.org
Forgot your password?