Changes to PL/SQL programs can be recognized using the source code timestamp in the repository.
However, it is not clear whether effective PL/SQL code or only comments, white spaces or lower/upper case tokens were changed.
The function get_CodeHash4Cmp determines the hash code of the effective PL/SQL database stored code without white spaces, comments or changed lower/upper case tokens, so that proof of real code changes is possible by means of hash code comparison.
The program was deliberately programmed simply and transparently with GOTO’s in order to enable possible extensions without side effects.
After saving the get_CodeHash4Cmp function, the following application steps are possible:
select get_CodeHash4Cmp('<stored-code-name>') from dual;
You will get the SHA384 code hash so you can save it for later comparison:
select get_CodeHash4Cmp('<stored-code-name>', '<PLSQL-code-hash-to-compare>') from dual;
create or replace procedure prc_example(p_x VARCHAR2) is
/*
This is a PL/SQL code demo for code hashing.
F.Matz : 2020-10-19
--
*/
l_y NUMBER;
begin
-- get PI --
l_y := acos(-1);
dbms_output.put_line(l_y);
end prc_example;
select get_codehash4cmp('PRC_EXAMPLE') from dual;
E030996282B21D2083F518741C49531ED528F3D6FA04E56726BA7ACCC27E2718BDAEA4946DB936E524B78F7FEC78673A
create or replace PROCEDURE Prc_Example(p_x VARCHAR2) IS
/*
This is a PL/SQL code demo for code hashing.
F.Matz : 2020-10-19
-- comment changed !
*/
l_y NUMBER;
BEGIN
-- get PI --
-- new comment ... --
l_y := Acos(-1);
dbms_output.put_line(l_y);
END Prc_Example;
select get_codehash4cmp('PRC_EXAMPLE_CHANGED', 'E030996282B21D2083F518741C49531ED528F3D6FA04E56726BA7ACCC27E2718BDAEA4946DB936E524B78F7FEC78673A') from dual;
=> PRC_EXAMPLE : OK'
That's all.