Bitwise exclusive OR in Oracle

十年热恋 提交于 2019-12-01 15:51:43

问题


In SQL Server I have been using the ^ symbol, however that doesn't seem to work in Oracle.

How do I do a bitwise exclusive OR in Oracle?


回答1:


From the docs:

function bitor(p1 number, p2 number) return number is
begin
  return p1-bitand(p1,p2)+p2;
end;

function bitxor(p1 number, p2 number) return number is
begin
  return bitor(p1,p2)-bitand(p1,p2);
end;

To see that these work, follow the logic with just 0s and 1s for input, and then not that there are no borrow or caries.

-- MarkusQ




回答2:


There is the BITAND operator:

select bitand(49,54)+0 from dual;

You can build up the other operators from it; and here.




回答3:


There's no easy way.

You may cast string HEX values into RAW values and use UTL_RAW:

SELECT UTL_RAW.bit_xor(HEXTORAW(TO_CHAR(1, 'FMX')), HEXTORAW(TO_CHAR(2, 'FMX')))
FROM dual

---
 03


来源:https://stackoverflow.com/questions/604598/bitwise-exclusive-or-in-oracle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!