Here is the thing. I have an array of 0 and 1. It is supposed to be a binary string. What i need is to format it to string that contains base36 conversion from that binary.
In other words, i need to do this: array of 1 and 0 -> some kind of binary number -> convert to base36 number -> put it into string.
How to do that?
Thousands of oil, 300 steel and +1 luck to answerers.
There is no Oracle built-in to do this sort of conversion. In the following example I use two functions witten by the inestimable Mr Kyte.
to_dec()turns other bases to decimals, andto_base()turns decimals into other bases.The procedure takes an array of ones and zeroes and returns a string of base 36.
The proof of the pudding and all that …
edit
While I was assembling this sample you posted that your array of zeroes was ~450 entries long. This routine won’t handle anything like that. It will hurl
ORA-01426: numeric overflowway before you hit a number of that size.edit 2
If you are happy to gamble with a little imprecision, you could replace the NUMBER variables with BINARY_DOUBLE variables (in both my sample and Tom’s functions). That datatype can handle much bigger numbers. I cranked it up to
array_count=470, which might look like this in base 36 :