Bitwise operations

Posted by

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 comments

  1. … 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

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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