Solved

Bitwise operator in Oracle

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Last record chosen in Oracle Query 3 54
Array of Key/Value Pairs as input to Oracle function 10 53
Oracle SQL 6 48
Oracle sql query 7 51
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 …
Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This video shows how to recover a database from a user managed backup

862 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now