sql >> Base de Datos >  >> RDS >> Oracle

Cómo implementar ora_hash (hash sembrable que divide cualquier tipo de datos sql en n cubos)

Creo que estás hablando de una función hash perfecta. La función ORA_HASH de Oracle no es una función hash perfecta.

http://en.wikipedia.org/wiki/Perfect_hash_function

Lo más cerca que llegará a lo que parece querer es una matriz asociativa. Oracle los tiene. Comience a jugar con este ejemplo:

set serverout on size 10000
DECLARE
cursor foo 
is 
  select distinct fld1,fld2,fld9  from sometable;

type t is table of foo.%ROWTYPE
  index by varchar2;   -- change the index to an int if you want

myarray t; -- myarray is a table of records -- whatever foo returns

BEGIN
  for x in foo
  loop
      -- index using the first column of the fetched row  "fld1":
      myarray(x.fld1)=x;  -- assign the rowtype to the table of records.      
  end loop;

END;
/  

Nota:una matriz asociativa se crea en una tabla hash, el ejemplo anterior usa fld1 como la clave hash. Por lo tanto, lo anterior solo funcionará si, como usted describe, hashing perfecto, si y solo si fld1 es un campo único. Eso es lo que los distintos en allí para hacer. Nunca siempre es necesario.