Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to do bitwise operations in Oracle 1

Status
Not open for further replies.

amortillaro

Programmer
Dec 1, 2003
25
US
Hi guys:
I didn't found any bitwise operators in oracle, so I suppouse I should build a function for this (let me know if I'm wrong).
Then how can I convert a number to it's binary representation in oracle?

byte=1: 0000 0001
byte=4: 0000 0100
result: 0000 0101

Thank's.. Aishel
 
another example...

5 - 0101
3 - 0011
---------- and operation
1 - 0001

.
 
here is an extension to Or and Xor

function bitor(p_dec1 number, p_dec2 number) return number is
begin
return p_dec1-bitand(p_dec1,p_dec2)+p_dec2;
end;

function bitxor(p_dec1 number, p_dec2 number) return number is
begin
return bitor(p_dec1,p_dec2)-bitand(p_dec1,p_dec2);
-- or you could use: return p_dec1-2*bitand(p_dec1,p_dec2)+p_dec2;
end;
Further information about bitwise operation in oracle can be found in .

Thanks for your help, greetings. Aishel
 
Here's one I like:
This is written in MySQL and to translate to oracle, the first part of the select would probably go
something like this:

select name
from survey
where bitand(status, 8) !=0
and bitand(status, 7) = 0

define('STATUS_ACTIVE', 0x01);
define('STATUS_DONE', 0x02);
define('STATUS_DELETED', 0x04);
define('STATUS_TEST', 0x08);

$statusbad = (STATUS_DONE | STATUS_DELETED | STATUS_ACTIVE);
$statusok = STATUS_TEST;
if($HTTP_SESSION_VARS['acl']['superuser'] == 'Y') {
$sql = "SELECT id,name,title,owner,realm FROM survey
WHERE (status & $statusok)
AND NOT (status & $statusbad)
ORDER BY id DESC";
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top