In the Oracle documentation, the specification for ORA_HASH is:
The optional max_bucket argument determines the maximum bucket value returned by the hash function. You can specify any value between 0 and 4294967295. The default is 4294967295.
So when I had a set of attributes come in, and I was looking for a simple way of mapping them to a simple unique key, ORA_HASH seemed the natural choice. Until this happened…
SQL> create table T (
2 id varchar2(8),
3 code varchar2(5),
4 year varchar2(4)
5 );
Table created.
SQL> insert into T values ('240301','21806','2004');
1 row created.
SQL> insert into T values ('276083','31808','2010');
1 row created.
SQL> select id, code, year, ora_hash(id||code||year) hash
2 from t;
ID CODE YEAR HASH
-------- ----- ---- ----------
240301 21806 2004 1018600323
276083 31808 2010 1018600323
My table has only 90,000 rows, so (assuming a roughly equal distribution of hash keys) I had a 0.002% chance of hitting that
Oracle karma 🙂




Got some thoughts? Leave a comment