Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

Why am I getting 2 instead of 3 when I perform BIT_OR(2,1)?

SELECT UTL_RAW.CAST_TO_NUMBER (              --> decimal: 3? nope, 2
            UTL_RAW.BIT_OR(                  --> binary: 11? shouldn't it?
                UTL_RAW.CAST_FROM_NUMBER(2), --> binary: 10
                UTL_RAW.CAST_FROM_NUMBER(1)  --> binary:  1
            )
        )
FROM DUAL;
share|improve this question
add comment

1 Answer

CAST_FROM_NUMBER returns RAW; if you check result of UTL_RAW.CAST_FROM_NUMBER(2) , it's not 2 but "C103" (which I believe means (03-1)* pow(10,(0xC1-0xC1))) . You need something like

SELECT   UTL_RAW.CAST_TO_BINARY_INTEGER(UTL_RAW.BIT_OR(
            UTL_RAW.CAST_FROM_BINARY_INTEGER(2), 
            UTL_RAW.CAST_FROM_BINARY_INTEGER(1)  
        ))

FROM DUAL;

Some links about internal number representations: http://www.jlcomp.demon.co.uk/number_format.html , http://docs.oracle.com/cd/E11882_01/appdev.112/e10646/oci03typ.htm
Your code returns result of C103(internal representation of 2) & C102(internal representation of 1) which is 2

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.