---
title: "[转]Oracle bitand()函数"
author: "liumiao2011"
date: "2013-04-15T15:42:10Z"
tags: []
categories: ["数据库"]
slug: "oracle-bitand"
draft: false
lastmod: "2013-04-15T15:42:10Z"
id: 1847660
url: "https://liumiao2011.iteye.com/blog/1847660"
---

**bitand( ) 函数**   

  返回两个数值型数值在按位进行    AND    运算后的结果。     
   语法     
   BITAND(nExpression1,    nExpression2)     
   参数     
   nExpression1,    nExpression2     
      
   指定按位进行    AND    运算的两个数值。如果    nExpression1    和    nExpression2    为非整数型，那么它们在按位进行    AND    运算之前转换为整数。     
      
   返回值类型     
   数值型         
      
   **说明**     
   **BITAND()    将    nExpression1    的每一位同    nExpression2    的相应位进行比较。如果    nExpression1    和    nExpression2    的位都是    1，相应的结果位就是    1；否则相应的结果位是    0。**   

   下表列出对    nExpression1    和    nExpression2    按位进行    AND    运算的结果：     
      
   nExpression1    位    nExpression2    位    结果位       
   0    0    0       
   0    1    0       
   1    1    1       
   1    0    0       
   bitand(    )    函数示例     
   x    =    5      &&    二进制为    0101     
   y    =    6      &&    二进制为    0110     
   ?    bitand(x,y)    &&    返回值    4，二进制为    0100   

\-----------------------------------------------------------------------------

ORACLE中的BITOR和BITXOR

ORACLE中只有BITAND而没有BITOR, BITXOR

原因是，有了BITAND, 很容易实现BITOR和BITXOR

 

BITOR(x,y) = (x + y) - BITAND(x, y);

BITXOR(x,y) = BITOR(x,y) - BITAND(x,y) = (x + y) - BITAND(x, y) * 2;