ID Automation
ID Automation
begin
for i in 1..length(p_string)
loop
if substr(p_string, i, 1) not in ('1','2','3','4','5','6','7','8','9','0') then
return false;
end if;
end loop;
return true; -- All the characters are numbers
end;
begin
end postnet;
begin
-- Only keep numbers; Leading and Trailing spaces will be removed as well
for i in 1..length(p_data_to_encode)
loop
if is_number(substr(p_data_to_encode,i,1)) then
onlyCorrectData := onlyCorrectData || substr(p_data_to_encode,i,1);
end if;
end loop;
for i in 1..length(onlyCorrectData)
loop
-- Only execute this loop every second time eg. when i = 1,3,5,7, etc...
if mod(i,2) = 1 then
currentCharNum := to_number(substr(onlyCorrectData,i,2));
-- Get the ASCII Value of the current char according to chart
if currentCharNum < 94 then printableString := printableString ||
chr(currentCharNum + 33); end if;
if currentCharNum >= 94 then printableString := printableString ||
chr(currentCharNum + 103); end if;
end if; -- mod(i,2)
end loop;
end I2of5;
factor number := 3;
begin
-- Only keep numbers; Leading and Trailing spaces will be removed as well
for i in 1..length(p_data_to_encode)
loop
if is_number(substr(p_data_to_encode,i,1)) then
onlyCorrectData := onlyCorrectData || substr(p_data_to_encode,i,1);
end if;
end loop;
-- Find the check digit by finding the smallest number that = a multiple of 10
if mod(weightedTotal,10) <> 0 then
check_digit := mod(weightedTotal,10);
else
check_digit := 0;
end if;
for i in 1..length(onlyCorrectData)
loop
-- Only execute this loop every second time eg. when i = 1,3,5,7, etc...
if mod(i,2) = 1 then
currentCharNum := to_number(substr(onlyCorrectData,i,2));
-- Get the ASCII Value of the current char according to chart
if currentCharNum < 94 then printableString := printableString ||
chr(currentCharNum + 33); end if;
if currentCharNum >= 94 then printableString := printableString ||
chr(currentCharNum + 103); end if;
end if; -- mod(i,2)
end loop;
if p_return_type = 0 then
return startCode || printableString || endCode|| ' ';
elsif p_return_type = 1 then
return onlyCorrectData;
elsif p_return_type = 2 then
return check_digit;
else
return null;
end if;
end I2of5Mod10;
HumanReadableText varchar2(4000);
currentCharNum number;
currentChar varchar2(1);
currentEncoding varchar2(1);
weightedTotal number;
checkDigitValue number;
c128_CheckDigit varchar2(2);
stringLength number;
i number := 1;
currentValue number;
begin
dataToFormat := rtrim(ltrim(p_data_to_encode));
currentCharNum := ascii(substr(dataToFormat,1,1));
stringLength := length(dataToFormat);
i, 4))))
or ((i < stringLength) and (is_number(substr(dataToFormat, i, 1))) and
(is_number(substr(dataToFormat, i+1, 1))) and (currentEncoding = 'C'))
then
-- switch to set C if not already in it
if currentEncoding <> 'C' then
dataToEncode := dataToEncode || chr(199);
end if;
currentEncoding := 'C';
currentValue := to_number(substr(dataToFormat,i,2));
-- set the currentValue to the number of String currentChar
if currentValue < 95 and currentValue > 0 then
dataToEncode := dataToEncode || chr(currentValue + 32);
end if;
if currentValue >= 95 then
dataToEncode := dataToEncode || chr(currentValue + 100);
end if;
if currentValue = 0 then
dataToEncode := dataToEncode || chr(194);
end if;
i := i + 1;
-- check for switching to character set A
elsif (i <= stringLength)
and ((ascii(substr(dataToFormat,i,1)) < 31)
or ((currentEncoding = 'A') and (ascii(substr(dataToFormat,i,1)) > 32 and
(ascii(substr(dataToFormat,i,1))) < 96))) then
-- switch to set A if not already in it
if currentEncoding <> 'A' then
dataToEncode := dataToEncode || chr(201);
end if;
currentEncoding := 'A';
end loop;
-- divide the weightedTotal by 103 and get the remainder, this is the CheckDigit
checkDigitValue := mod(weightedTotal, 103);
-- Now that we have the CheckDigit Value, find the corresponding ASCII character
from the table
if checkDigitValue < 95 and checkDigitValue > 0 then c128_CheckDigit :=
chr(checkDigitValue + 32); end if;
if checkDigitValue >= 95 then c128_CheckDigit := chr(checkDigitValue + 100); end
if;
if checkDigitValue = 0 then c128_CheckDigit := chr(194); end if;
for j in 1..length(dataToEncode)
loop
currentChar := substr(dataToEncode, j, 1);
-- Replace spaces with chr(194)
if currentChar = ' ' then
currentChar := chr(194);
end if;
dataToPrint := dataToPrint || currentChar;
end loop;
if p_return_type = 0 then
return c128Start || dataToPrint || c128_CheckDigit || c128Stop;
elsif p_return_type = 1 then
return HumanReadableText;
elsif p_return_type = 2 then
return c128_CheckDigit;
end if;
end Code128;
-- Calcuation variables
weight_total number := ascii(start_character) - 100;
begin
end loop;
-- Get the check digit value
check_digit := mod(weight_total,103);
-- Get the corresponding character from the check_digit
if check_digit < 95 and check_digit > 0 then
check_digit_char := chr(check_digit + 32);
elsif check_digit >= 95 then
check_digit_char := chr(check_digit + 100);
elsif check_digit = 0 then
check_digit_char := chr(194);
end if;
-- check digit determined
end;
-- Calcuation variables
weight_total number := ascii(start_character) - 100;
begin
end loop;
-- Get the check digit value
check_digit := mod(weight_total,103);
-- Get the corresponding character from the check_digit
if check_digit < 95 and check_digit > 0 then
check_digit_char := chr(check_digit + 32);
elsif check_digit >= 95 then
check_digit_char := chr(check_digit + 100);
elsif check_digit = 0 then
check_digit_char := chr(194);
end if;
-- check digit determined
end;
-- Calcuation variables
weight_value number := 1;
weight_total number := 105;
begin
-- The string must be an even length, if not append a zero to the beginning of
it.
if mod(length(data_to_encode_char),2) = 1 then
data_to_encode_char := lpad(data_to_encode_char,length(data_to_encode_char)
+1,'0');
end if;
for i in 1..length(data_to_encode_char)
loop
if mod(i,2) = 1 then -- skep every second value
current_value := to_number(substr(data_to_encode_char, i, 2));
if current_value < 95 and current_value > 0 then
encoded_string := encoded_string || chr(current_value + 32);
end;
currentCharNum number;
weightedTotal number := 0;
currentValue number;
checkDigitValue number;
checkDigit number;
begin
for i in 1..length(v_data_to_encode)
loop
-- Get each character one at a time
currentCharNum := ascii(substr(v_data_to_encode,i,1));
-- Get the value of CurrentChar according to MOD43
-- 0-9
if currentCharNum between 48 and 57 -- 0-9
or currentCharNum between 65 and 90 -- A-Z
or currentCharNum in (32,45,46,36,47,43,37) then -- Space,-,.,$,/,+,%
onlyCorrectData := onlyCorrectData || substr(v_data_to_encode,i,1);
end if;
end loop;
v_data_to_encode := onlyCorrectData;
for i in 1..length(v_data_to_encode)
loop
-- Get each character one at a time
currentCharNum := ascii(substr(v_data_to_encode,i,1));
-- Get the value of CurrentChar according to MOD43
-- 0-9
if currentCharNum between 48 and 57 then currentValue := currentCharNum - 48; end
if;
-- A-Z
if currentCharNum between 65 and 90 then currentValue := currentCharNum - 55; end
if;
-- Space
if currentCharNum = 32 then currentValue := 38; end if;
-- -
if currentCharNum = 45 then currentValue := 36; end if;
-- .
if currentCharNum = 46 then currentValue := 37; end if;
-- $
if currentCharNum = 36 then currentValue := 39; end if;
-- /
if currentCharNum = 47 then currentValue := 40; end if;
-- +
if currentCharNum = 43 then currentValue := 41; end if;
-- %
if currentCharNum = 37 then currentValue := 42; end if;
end loop;
-- Divide the weightedTotal by 43 and get the remainder for check digit
checkDigitValue := mod(weightedTotal,43);
end Code39Mod43;
ean5addon varchar2(5);
ean2addon varchar2(2);
eanaddonToPrint varchar2(100);
encoding varchar2(10);
currentEncoding varchar2(1);
begin
-- Only keep numbers and remove dashes
for i in 1..length(v_data_to_encode)
loop
if is_number(substr(v_data_to_encode,i,1)) then onlyCorrectData :=
onlyCorrectData || substr(v_data_to_encode,i,1); end if;
end loop;
-- Find the check digit by finding the number + weightedTotal that = a multiple
of 10
-- Divide by 10, get the remainder and subtract from 10
if mod(weightedTotal, 10) <> 0 then
checkDigit := 10 - mod(weightedTotal,10);
else
checkDigit := 0;
end if;
end if;
end loop;
-- Process 5 digit add on if it exits
if length(ean5addon) = 5 then
-- Get check digit for add on
factor := 3;
weightedTotal := 0;
for i in reverse 1..length(ean5addon)
loop
-- Get the value of each number starting at the end
currentCharNum := substr(ean5addon, i, 1);
-- Multiply by the weighting factor which is 3,9,3,9, ....
-- and add the sum together
if factor = 3 then weightedTotal := weightedTotal + (currentCharNum * 3);
end if;
if factor = 1 then weightedTotal := weightedTotal + (currentCharNum * 9);
end if;
-- Change the factor for the next calculation
factor := 4 - factor;
end loop;
factor number := 3;
weightedTotal number := 0;
currentCharNum number;
checkDigit number;
wrong_length exception;
begin
-- Clean up the data by removing keeping numbers and removing dashes
for i in 1..length(dataToEncode)
loop
if is_number(substr(dataToEncode, i, 1)) then
onlyCorrectData := onlyCorrectData || substr(dataToEncode, i, 1);
end if;
end loop;
dataToEncode := onlyCorrectData;
exception
when wrong_length then
raise_application_error(-20001,'Cannot process this barcode. Please enter a 7
digit number for an EAN8 barcode. Do not use any spaces or dashes');
end EAN8;
currentCharNum number;
currentChar varchar2(1);
factor number := 3;
weightedTotal number := 0;
ean5AddOn varchar2(10);
ean2AddOn varchar2(10);
eanAddOnToPrint varchar2(20);
checkDigit number;
leadingDigit number;
encoding varchar2(15);
currentEncoding varchar2(1);
begin
-- Only keep numbers and remove dashes
for i in 1..length(dataToEncode)
loop
if is_number(substr(dataToEncode, i, 1)) then onlyCorrectData :=
onlyCorrectData || substr(dataToEncode, i, 1); end if;
end loop;
-- Find the check digit by finding the number + weightedTotal that = a multiple
of 10
-- divide by 10, get the remainder and subtract from 10
if mod(weightedTotal,10) <> 0 then
checkDigit := 10 - mod(weightedTotal,10);
else
checkDigit := 0;
end if;
-- Encode the leading digit into the left half of the EAN-13 symbol
-- by using variable parity between character sets A and B
leadingDigit := substr(dataToEncode,1,1);
if leadingDigit = 0 then encoding := 'AAAAAACCCCCC';
elsif leadingDigit = 1 then encoding := 'AABABBCCCCCC';
elsif leadingDigit = 2 then encoding := 'AABBABCCCCCC';
elsif leadingDigit = 3 then encoding := 'AABBBACCCCCC';
elsif leadingDigit = 4 then encoding := 'ABAABBCCCCCC';
elsif leadingDigit = 5 then encoding := 'ABBAABCCCCCC';
elsif leadingDigit = 6 then encoding := 'ABBBAACCCCCC';
elsif leadingDigit = 7 then encoding := 'ABABABCCCCCC';
elsif leadingDigit = 8 then encoding := 'ABABBACCCCCC';
elsif leadingDigit = 9 then encoding := 'ABBABACCCCCC';
end if;
-- Add the check digit to the end of the barcode & remove the leading digit
dataToEncode := substr(dataToEncode, 2, 11) || checkDigit;
eanAddOnToPrint := eanAddOnToPrint;
end if;
end loop;
end if; --ean2AddOn
end EAN13;
end;
/