Friday, December 12, 2008

Number Conversion Routines (By Thomas Kyte)

This set of routines is useful to convert between various 'bases' in Oracle. Once you install these functions, you will be able to perform operations such as

select to_bin( 123 ) bin, to_hex( 123 ) hex, to_oct( 123 ) oct from dual;

Just follow the links:

for examples -> http://asktom.oracle.com/tkyte/hexdec/index.html

for the code -> http://asktom.oracle.com/tkyte/hexdec/hexdec.sql

Using the above functions you can do right shifting
e.g

select lpad( to_bin( 3123 ), 15, '0' ) bin1,
lpad( to_bin( trunc(3123/power(2,(rownum-1))) ), 15, '0' ) bin2,
rownum-1 shift
from all_users
where rownum <= 10;



No comments:

Post a Comment