I want to convert a byte string like '1001' to the integer value 9, is there a standard function for that in Oracle ?
BTW I found a custom solution on http://www.orafaq.com/wiki/Binary
I was trying this on Oracle
using CONNECT BY
to convert binary to decimal in simple SELECT
statement. Finally got the desired output using below code.
WITH INPUT AS
(SELECT REVERSE('&N') AS X FROM DUAL)
SELECT SUM(TO_NUMBER(SUBSTR(X,LEVEL,1)*POWER(2,LEVEL-1))) AS OUTPUT
FROM INPUT CONNECT BY LEVEL<=LENGTH(X);
AFAIK there's no a built in function in Oracle for that, though you can use solution provided int he link in your post
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With