Search code examples
oraclebitmask

PLSQL bitmask values


I am in this situation, I cannot validate the bit for the print permission. Unfortunately I can't have a bitmask with a single bit lit. Can you give me some suggestions?

SELECT 
  DECODE(BITAND(00000000100000100000000000000001, 1), 1, '1', '0') AS READ,
  DECODE(BITAND(00000000100000100000000000000001, 131072), 131072, '1', '0') AS COPY,
  DECODE(BITAND(00000000100000100000000000000001, 8388608), 8388608, '1', '0') AS PRINT
  FROM 
DUAL

The result is the following

R C P
- - -
1 1 0

Can you give me some suggestions?


Solution

  • enter image description here

    The BIT_AND function has both arguments as numbers, and there is no bit vector.

    For example:

    select bin_to_num(0,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1) from dual;
    
    OUTPUT>
    8519681
    
    
    with 
    datum as
    (select bin_to_num(0,0,0,0,0,0,0,0,1/*print*/,0,0,0,0,0,1/*copy*/,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1/*read*/) val from dual)
    select 
      decode(bitand(val, 1), 1, '1', '0') as read,
      decode(bitand(val, 131072), 131072, '1', '0') as copy,
      decode(bitand(val, 8388608), 8388608, '1', '0') as print
    from  datum 
    

    enter image description here