user2483797
user2483797

Reputation: 169

Converting guids to numeric value

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.

Upvotes: 2

Views: 3099

Answers (3)

Ed Gibbs
Ed Gibbs

Reputation: 26343

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;

Upvotes: 6

Legionar
Legionar

Reputation: 7597

This will convert MD5 hash (hex) to decimal number

SELECT CONV('MD5', 16, 10)
FROM PRODS;

Upvotes: 1

Steve Martin
Steve Martin

Reputation: 1642

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

Upvotes: 1

Related Questions