I have had the need to verify that a particular pl/sql object (say a procedure) matches between development, test, and production environments. In order to compare and know with 100% certainty that the code matches, I have written a simple function such as this:
function get_plsql_hash (p_owner varchar2, p_name varchar2, p_type varchar2) return number as
v_hash number;
begin
select sum(ora_hash(line||'!'||text)) into v_hash
from dba_source
where owner = p_owner
and name = p_name
and type = p_type;
if v_hash is null then
return 0;
else
return v_hash;
end if;
exception
when others then
return 0;
end get_plsql_hash;
It works great. If I change even just one character of code, I will get a different hash value (checksum or whatever you want to call it). I am able to use Oracle dictionary views to not only verify pl/sql code, but also data in reference/lookup tables, table structure, table privs, indexes, constraints, sequences, etc. The function I pasted above was just one example.
Here is my question.... does something in the Oracle data dictionary already exist that I do not know about that could give me a unique value representing each object? It would be awesome if dba_objects had a column named OBJ_CKSUM or something similar. If Oracle could keep this internally every time an object is modified, it would completely eliminate the need for the code I wrote (which is only a few hundred lines, but zero lines with no code to maintain is far superior). If such a feature does not exist, would Oracle possibly consider adding this in a future release? I think it is very helpful, but I am not sure if other developers, testers, or release management would agree. I do not know how to proceed with requesting a feature from Oracle.