oracle PL/SQL 中有散列函数吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5595774/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is there any hash function in PL/SQL?
提问by jomaora
I'm looking for a Hash function in PL/SQL, to get the hash of a varchar. I found a package in Oracle 10 called dbms_crypto with a function dbms_crypto.hash and even other package dbms_sqlhash.getHash, however where I called them, I've got a message like it cannot find them...
我正在寻找 PL/SQL 中的哈希函数,以获取 varchar 的哈希值。我在 Oracle 10 中找到了一个名为 dbms_crypto 的包,其中包含一个函数 dbms_crypto.hash 甚至其他包 dbms_sqlhash.getHash,但是在我调用它们的地方,我收到一条消息,就像它找不到它们一样......
Does somebody know how can I call them?? Is there any other package?
有人知道我怎么称呼他们吗??有没有其他的包?
Here's my code
这是我的代码
DECLARE
l_textToHash VARCHAR2(19) := 'toto123';
l_ccn_raw RAW(128) := utl_raw.cast_to_raw(l_textToHash);
l_encrypted_raw RAW(2048);
BEGIN
dbms_output.put_line('CC: ' || l_ccn_raw);
l_encrypted_raw := dbms_crypto.hash(l_ccn_raw, 3);
dbms_output.put_line('SH1: ' || l_encrypted_raw);
END;
/
Here's the message
这是消息
Error starting at line 1 in command:
DECLARE
l_textToHash VARCHAR2(19) := 'toto123';
l_ccn_raw RAW(128) := utl_raw.cast_to_raw(l_textToHash);
l_encrypted_raw RAW(2048);
BEGIN
dbms_output.put_line('CC: ' || l_ccn_raw);
l_encrypted_raw := dbms_crypto.hash(l_ccn_raw, 3);
dbms_output.put_line('SH1: ' || l_encrypted_raw);
END;
Error report:
ORA-06550: line 7, column 22:
PLS-00201: identifier 'DBMS_CRYPTO' must be declared
ORA-06550: line 7, column 3:
PL/SQL: Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
Thanks!
谢谢!
回答by Justin Cave
Depending on why you're trying to generate the hash, the built-in function ORA_HASH may be sufficient,
根据您尝试生成哈希的原因,内置函数 ORA_HASH 可能就足够了,
SQL> select ora_hash( 'fuzzy bunny' ) from dual;
ORA_HASH('FUZZYBUNNY')
----------------------
2519249214
I wouldn't try to use this if you need a cryptographically secure hash function. But if you just need a simple hash, this should be sufficient.
如果您需要加密安全的哈希函数,我不会尝试使用它。但是如果你只需要一个简单的哈希,这应该就足够了。
回答by N West
Make sure that you have the appropriate permissions granted to the user that you are connecting with. Talk to your DBA to add the execute permission on the SYS.DBMS_CRYPTO package.
确保您已向要连接的用户授予适当的权限。与您的 DBA 联系以添加对 SYS.DBMS_CRYPTO 包的执行权限。
Oracle provides a nice guideon working with hashed and encrypted data using the oracle database.
Oracle 提供了关于使用 oracle 数据库处理散列和加密数据的很好的指南。
If you are on an older version of the database that doesn't support DBMS_CRYPTO, you can also try DBMS_OBFUSCATION_TOOLKIT.
如果您使用的是不支持 DBMS_CRYPTO 的旧版本数据库,您还可以尝试 DBMS_OBFUSCATION_TOOLKIT。
In Oracle 12c you can use the function STANDARD_HASH.
在 Oracle 12c 中,您可以使用函数STANDARD_HASH。