我查看了关于哈希表的维基百科文章,但它似乎没有说明如何实现一个哈希表,该哈希表可以将任意 SQL 数据类型的条目均匀地分配到 n 个存储桶中。
谁能指出我关于这个主题的文档或现有源代码的方向?
我相信你在谈论一个完美的哈希函数。Oracle 的 ORA_HASH 函数并不是一个完美的散列函数。
http://en.wikipedia.org/wiki/Perfect_hash_function
尽可能接近您似乎想要的是一个关联数组。甲骨文有这些。开始玩这个例子:
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;
/
注意:关联数组是建立在哈希表上的,上面的例子使用 fld1 作为哈希键。因此,只有当且仅当 fld1 是唯一字段时,上述方法才有效。这就是那里的独特之处。它从来都不是必需的。