Generate code in Oracle

The idea is as follows. We want to create a simple function that calculates a code from a string. This code is the total ASCII value of the characters in a string. I used this code to act as a foreign key to which other tables may refer to.

I use an Oracle function that is written as:

create or replace
function sumascii (str in varchar2) return number is
x number := 0;
begin
for i in 1..length (str)
loop
x := x + i*ascii (substr (str, i, 1)) ;
end loop;
return x;
end;
/

This function can be used in a SQL statement. For example, one may insert the codes as: update mappings set sleutel = sumascii(mapping);