?
Solved

Bitwise operator in Oracle

Posted on 2000-04-02
4
Medium Priority
?
1,091 Views
Last Modified: 2012-08-14
I'm porting stored procedures from Sybase to Oracle 8i but I can't find any bitwise operator in Oracle. Is there any? If not please give me a way to do it (AND, OR, XOR, NOT operators).
0
Comment
Question by:daitt
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 4

Expert Comment

by:sudhi022299
ID: 2678893
In Oracle AND, OR and NOT operators are supported. XOR could be implemented i think.
0
 
LVL 3

Author Comment

by:daitt
ID: 2679031
Please give me a simple example of using them in a Stored Procedure.
Just print out (5 AND 7) for example.
Thanks
0
 
LVL 4

Accepted Solution

by:
syakobson earned 200 total points
ID: 2680342
sudhi,
AND, OR and NOT are LOGICAL not BITWISE operators. They take TRUE/FALSE operands only. PL/SQL provides UTL_RAW package which will allow you to perform BITWISE operations against either raw datatype or strings assigned HEX values:

SQL> declare a varchar2(2);
  2  b varchar2(2);
  3  begin
  4  a := '&1';
  5  b := '&2';
  6  dbms_output.put_line(a || ' AND ' || b || ' = ' || utl_raw.bit_and(a,b));
  7  dbms_output.put_line(a || ' OR  ' || b || ' = ' || utl_raw.bit_or(a,b));
  8  dbms_output.put_line(a || ' XOR  ' || b || ' = ' || utl_raw.bit_xor(a,b));
  9  dbms_output.put_line('NOT ' || a || ' = ' || utl_raw.bit_complement(a));
 10  end;
 11  /
Enter value for 1: 1F
old   4: a := '&1';
new   4: a := '1F';
Enter value for 2: F1
old   5: b := '&2';
new   5: b := 'F1';
1F AND F1 = 11
1F OR  F1 = FF
1F XOR  F1 = EE
NOT 1F = E0

PL/SQL procedure successfully completed.

Solomon Yakobson.
0
 
LVL 4

Expert Comment

by:sudhi022299
ID: 2680578
Sorry Solomon, i didn't read the question properly. But thanks for the UTL_RAW package though.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Truncate is a DDL Command where as Delete is a DML Command. Both will delete data from table, but what is the difference between these below statements truncate table <table_name> ?? delete from <table_name> ?? The first command cannot be …
Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
This video shows how to recover a database from a user managed backup
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question