Solved

Bitwise operator in Oracle

Posted on 2000-04-02
4
1,073 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
  • 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 50 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Why doesn't the Oracle optimizer use my index? Querying too much data Most Oracle developers know that an index is useful when you can use it to restrict your result set to a small number of the total rows in a table. So, the obvious side…
This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

808 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