ten-digit hexadecimal number [message #683076] |
Tue, 01 December 2020 01:31 ![Go to next message Go to next message](/forum/theme/orafaq/images/down.png) |
mape
Messages: 298 Registered: July 2006 Location: Slovakia
|
Senior Member |
|
|
Hello
I would like to ask you to give me an advice.
I need to generate unique ten-digit hexadecimal number.
It looks like this:
00037C534B
00037C55D0
00037C562B
Does anybody know how to do this the best ?
Thanks
Regards
Martin
|
|
|
|
|
Re: ten-digit hexadecimal number [message #683082 is a reply to message #683079] |
Tue, 01 December 2020 06:08 ![Go to previous message Go to previous message](/forum/theme/orafaq/images/up.png) ![Go to next message Go to next message](/forum/theme/orafaq/images/down.png) |
Solomon Yakobson
Messages: 3273 Registered: January 2010 Location: Connecticut, USA
|
Senior Member |
|
|
Michel,
Random != unique (also you need FM modifier otherwise TO_CHAR will produce 11 characters - leading space for plus sign). Chance of duplicate GUID is exteremely low and even though substr 10 out of 16 hex digits from GUID makes that chance a bit higher it is still extermely low but it exists. OP can simply use sequence to get 100% guaranteed uniqueness:
SQL> create sequence seq;
Sequence created.
SQL> select to_char(seq.nextval,'FM000000000X') hex10
2 from dual
3 connect by level <= 32
4 /
HEX10
-----------
0000000021
0000000022
0000000023
0000000024
0000000025
0000000026
0000000027
0000000028
0000000029
000000002A
000000002B
000000002C
000000002D
000000002E
000000002F
0000000030
0000000031
0000000032
0000000033
0000000034
0000000035
0000000036
0000000037
0000000038
0000000039
000000003A
000000003B
000000003C
000000003D
000000003E
000000003F
0000000040
32 rows selected.
SQL>
[Updated on: Tue, 01 December 2020 06:12] Report message to a moderator
|
|
|
|
|
|
|
|