3 Replies Latest reply: Jul 11, 2013 7:09 AM by user7209195

# EAN-13 checksum

I need to validate the input of EAN-13 check digit
I use FORMS 4.5 & ORCALE DB 9i

2741023456884 (this is the scanned input)

2*1
7*3
4*1
1*3
0*1
2*3
3*1
4*3
5*1
6*3
8*1
8*3

2 + 21 + 4+3+0+6+3+12+5+18+8+24=106

106/10 = 10 remainder 6

10-6 =4 ( 4 matches the check digit in the above input last digit)

Note: if the remainder is 0 then 10 -0 = 10 and the check digit is the right most digit which is 0

Can any help me with this procedure, has any one did this before.

Thanks for you help in advance
• ###### 1. Re: EAN-13 checksum
Something as,
SELECT
CASE
WHEN 10- mod ( (substr(a,2) + substr(a,4).... + substr(a,12) ) * 3 +
( substr(a,1) + substr(a,3) + ..... substr(a,11) ), 10) = substr(a,13)
THEN 'Ok'
ELSE 'No'
END
From dual;
replace 'a' with your value and complete

** Untested

Best Regards
• ###### 2. Re: EAN-13 checksum
Provided by citrus
================
to validate the check digit for EAN-13 will be helpful to some of you guys.

create or replace function ean_13(P_Str In Varchar2) Return Varchar2 Is
l_Sum Number;
l_Multiple Number;
Begin
For I in 1..12 Loop
If mod(i,2) = 0 Then
l_Multiple := 3;
Else
l_Multiple := 1;
End If;

l_Sum := Nvl(l_Sum, 0) + Substr(P_Str, i, 1) * l_Multiple;
End Loop;

If 10 - Mod(l_Sum, 10) = Substr(P_Str, 13) Then
Return('TRUE');
Else
Return('FALSE');
End If;
End;
/

FOLLOWING EAN-13 barcodes has been test
2741023456884
TRUE

27410000322652
FALSE

2741004189978
TRUE
2741012605675
TRUE
2741012605668
TRUE
2741012605651
TRUE
2741012605644
TRUE

Thanks
• ###### 3. Re: EAN-13 checksum

If not too obsolete Oracle version I used to run:

with test as (

select '4028460520162' ean from dual

)

select substr(10-mod(sum(to_number(substr(reverse(ean),2+level-1,1))*(mod(level,2)*2+1)),10),-1)

from test

connect by level <= length(substr(reverse(ean),2));