Question

What is the best way to obtain the numeric value from a guid column?

I am trying this line but i am getting:

ORA-00904: "HASHBYTES": invalid identifier
00904. 00000 -  "%s: invalid identifier"

Query is below:

SELECT HASHBYTES('MD5',CAST(prod AS varchar2(30)))
FROM PRODS;

Please advice.

Was it helpful?

Solution

Oracle doesn't have the HASHBYTES function. You can convert hex to decimal using TO_NUMBER(hex-string, 'xx'), but you must have enough x characters in your format string to cover the input value. In the case of a GUID, that's 32 x characters:

SELECT TO_NUMBER(prod, RPAD('x', 32, 'x'))
FROM PRODS;

OTHER TIPS

GUIDs don't really lend themselves to being represented as numerics. However, you can do it if you need to.

This question has been asked before in this post

This will convert MD5 hash (hex) to decimal number

SELECT CONV('MD5', 16, 10)
FROM PRODS;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top