The long existing BITAND function is now within the documentation, to let you do logical AND on two numbers, and is also available from PL/SQL

image

 

If you need other bit operations, a little boolean math should suffice Smile Just make sure you stay within the limits of BINARY_INTEGER


CREATE OR replace FUNCTION bitor( x IN binary_integer, y IN binary_integer ) RETURN binary_integer  AS
BEGIN
    RETURN x - bitand(x,y) + y;
END;
/

CREATE OR replace FUNCTION bitxor( x IN binary_integer, y IN binary_integer ) RETURN binary_integer  AS
BEGIN
    RETURN bitor(x,y) - bitand(x,y);
END;
/



2 responses to “Bitwise operations”

  1. It not only long existing, it has been documented since at least Oracle 8.17. https://docs.oracle.com/cd/A87860_01/doc/server.817/a85397/function.htm#98002

    And since that version it says in the PLSQL User Guide and Reference “PL/SQL lets you use all the SQL data manipulation, cursor control, and transaction control commands, as well as all the SQL functions, operators, and pseudocolumns.”

  2. … except for the SQL functions that aren’t supported, such as EXTRACT and other XML functions and BIN_TO_NUM, DUMP, MAKE_REF

    … and all of the analytic functions (wouldn’t it be great to be able to use these directly in PL/SQL like you can with MULTISET for object types).

Got some thoughts? Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Trending