Sample Header Ad - 728x90

Oracle Equivalent of SQL Server's Bitwise Operators

1 vote
1 answer
4982 views
I am trying to figure out all of the common bit-wise operations in Oracle. In SQL Server we have some very simple bit-wise operators to use against a bit-wise value: * & - Evaluates if bit exists select 10 & 2 /* result=2 */ * | - Add Bit (if doesn't exist) select 10 | 2 /* result=10 */ * &~ - Remove Bit (if exists) select 10 &~ 2 /* result=8 */ * ^ - Toggle Bit (remove if exists, adds if doesn't) select 10 ^ 2 /* result = 8 */ In Oracle, I know we have a built-in bitand() function which is more or less equivalent to SQL Server &, and I have built an Oracle bit-wise OR function to mimic SQL server's bit-wise OR operation (|) as follows: CREATE OR REPLACE FUNCTION BITOR (x IN NUMBER, y IN NUMBER) RETURN NUMBER AS BEGIN RETURN x + y - BITAND(x,y); END; **My question is**: how can I achieve the SQL Server &~ and the ^ operations in Oracle?
Asked by GWR (2847 rep)
Aug 2, 2016, 02:43 PM
Last activity: Aug 5, 2016, 04:54 PM