'Bitwise exclusive OR in Oracle

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?



Solution 1:[1]

There is the BITAND operator:

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

You can build up the other operators from it.

Solution 2:[2]

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

Solution 3:[3]

I use this for XOR in SQL:

--9 XOR 7 = 14
SELECT 7+9-2*bitand(7,9) FROM dual

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 sanitizedUser
Solution 2
Solution 3