dbms_crypto中hash_sh1的正确使用

在上一篇中提到了无法使用 dbms_crypto.hash_sh1

如果使用下面的SQL进行查询, 则会出现错误:
SQL> select dbms_crypto.hash(utl_raw.cast_to_raw(10), dbms_crypto.hash_sh1)
  2  from dual;                                                                                                 
select dbms_crypto.hash(utl_raw.cast_to_raw(10), dbms_crypto.hash_sh1)         
                                                                                     *                               
第 1 行出现错误:                                                                                            
ORA-06553: PLS-221: 'HASH_SH1' 不是过程或尚未定义                                   

跑asktom.oracle.com上去询问了, 早上来的时候就收到email通知该问题已经回答了,
解答如下:

because dbms_crypto.hash_sh1 is a PLSQL VARIABLE.
and you are not running PLSQL - just SQL.

if you did something like:
ops$tkyte%ORA10GR2> variable x refcursor                                                  
ops$tkyte%ORA10GR2> begin                                                                     
  2  open :x for                                                                                             
  3  select dbms_crypto.hash(utl_raw.cast_to_raw(10), dbms_crypto.hash_sh1)
from dual;                                                                                                    
  4  end;                                                                                                       
  5  /                                                                                                           

PL/SQL procedure successfully completed.                                                   

ops$tkyte%ORA10GR2> print x                                                                   

DBMS_CRYPTO.HASH(UTL_RAW.CAST_TO_RAW(10),:B1)                         
-------------------------------------------------------------------------------                                  
B1D5781111D84F7B3FE45A0852E59758CD7A87E5                                     

it would work - because PLSQL detects references to PLSQL variables and replaces them with bind variables....

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值