Friday, 8 March 2013

PLSQL iso7064 MOD 97,10 check

What is iso7064?

Check wikipedia
It is standard for checking accounting number on Credit cards, Resident Identity Card etc....

Rules for checking Mod97,10 (iso7061) are:

This scheme produces two digits as a check. And as a result, it catches just about every possible error. If you can afford the extra digit, this system is superior to the dihedral check.
It also has an especially compact formula. The check digits are given by mod(98 - mod(data * 100, 97), 97) and the verification is just mod(data_check,97) == 1. In practice an alternate algorithm (based on Horner's Rule) is used to avoid overflow issues.
Usage: banking

 So PLSQL code should look something like this ....

function f_control_iso7064(i_input in varchar2) as
   l_input varchar2(32767) := '123456789';
   e_exception exception;
   l_control_num number(10) := 0;
   -- as L_input not I
   l_input := trim(i_input);
   l_control_num := mod(98 - mod(l_input * 100, 97), 97);

   l_control_num:= mod(l_control_num,97);
   if l_control_num != 1 then
     return (false);
      return (true);  
    end if;
end f_control_iso7064;

Updated post: Had some issues with the code so changed line for check.... now it's good ;)


Post a Comment