Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert an 18 Character String into a Unique ID?

I have an 18 Character String that I need to convert into a unique long (in Java). A sample String would be: AAA2aNAAAAAAADnAAA

My String is actually an Oracle ROWID, so it can be broken down if needs be, see: http://download-uk.oracle.com/docs/cd/B19306_01/server.102/b14220/datatype.htm#CNCPT713

The long number generated, (1) Must be unique, as no two results can point to the same database row and (2) Must be reversible, so I can get the ROWID String back from the long?

Any suggestions on an algorithm to use would be welcome.

Oracle forum question on this from a few years ago : http://forums.oracle.com/forums/thread.jspa?messageID=1059740

Ro

like image 672
Ro. Avatar asked Nov 25 '09 15:11

Ro.


People also ask

How do you convert characters?

We can convert char to String in java using String. valueOf(char) method of String class and Character. toString(char) method of Character class.

What is string and unique string?

A Java String contains an immutable sequence of Unicode characters. Unlike C/C++, where string is simply an array of char , A Java String is an object of the class java. lang.

What is unique string in java?

A String is said to be 'Unique' if none of the letters present in the string are repeated. Write a program to accept a string and check whether the string is Unique or not.


1 Answers

You can't, with those requirements.

18 characters of (assuming) upper and lower case letters has 5618 or about 2.93348915 × 10331 combinations. This is (way) more than the approximate 1.84467441 × 1019 combinations available among 64 bits.

UPDATE: I had the combinatorics wrong, heh. Same result though.

like image 195
unwind Avatar answered Sep 28 '22 13:09

unwind