Solved

Bitwise operator in Oracle

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

Join & Write a Comment

Suggested Solutions

Article by: Swadhin
From the Oracle SQL Reference (http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/queries006.htm) we are told that a join is a query that combines rows from two or more tables, views, or materialized views. This article provides a glimps…
I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
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.
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.

760 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

18 Experts available now in Live!

Get 1:1 Help Now