Oracle get checksum value for a data chunk defined by a select clause

痞子三分冷 提交于 2019-11-28 12:50:56

You can use DBMS_SQLHASH.GETHASH for this. The query results must be ordered and must not contain any LOBs, or the results won't be deterministic.

select dbms_sqlhash.gethash(q'[select * from some_table order by 1,2]', digest_type => 1)
from dual;

Where digest_type 1 = HASH_MD4, 2 = HASH_MD5, 3 = HASH_SH1.

That package is not granted to anyone by default. To use it, you'll need someone to logon as SYS and run this:

SQL> grant execute on dbms_sqlhash to <your_user>;

The query results must be ordered, as described in "Bug 17082212 : DBMS_SQLHASH DIFFERENT RESULTS FROM DIFFERENT ACCESS PATH".

I'm not sure why LOBs don't work, but it might be related to the way the function ORA_HASH does not work well with LOBs. This Jonathan Lewis article includes some examples of ORA_HASH returning different results for the same LOB data. And recent versions of the SQL Language Reference warn that ORA_HASH does not support LOBs.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!