create or replace function f_eancode( in_zahlencode VARCHAR2, in_modus VARCHAR2 ) return varchar2 /******************************************************************** *Autor: Heiko Hommes *Beschr. *Übergabeparameper: Modus = C25 CODE 2/5 interleaved * C13 13er EAN Code mit Prüfziffer * C08 8er EAN *Zahlencode: Zahl, welche als ean gedruckt werden soll *Rückgabe: EAN-CODE , auf diesen Code ann man nun * die EAN-Schriftart drauf legen und der Barcode ist scanbar ********************************************************************/ IS l_fm varchar(255); ret_eancode varchar(20); v_code_25 varchar(8); v_code_13 varchar(13); v_code_8 varchar(8); v_ret number(1); v_count number(2); v_zahl number(3); c25_ts varchar2(2); c13_csatz varchar2(10); c13_absatz varchar2(20); i Number(2) := 0; nSum Number(20) := 0; Faktor Number(1) := 0; nPZ Number(2) := 0; BEGIN c13_csatz := '-yxcvbnm,.'; c13_absatz := 'pqwertzuioöasdfghjkl'; ret_eancode := '0'; --DBMS_OUTPUT.PUT_LINE('ZAHLENCODE: '||in_zahlencode); --DBMS_OUTPUT.PUT_LINE('MODUS: '||in_modus); v_ret := f_isnum(in_zahlencode); -- auf Zahl prüfen. if v_ret = 0 then ------------- ##################################################################### ------------- Start Modus P Prüfziffer ------------- ##################################################################### if in_modus = 'P' then v_code_13 := LPAD(in_zahlencode,12,'0'); Faktor := 1; FOR i IN 1 .. 12 LOOP nSum := nSum + To_Number(SUBSTR(in_zahlencode,i,1)) * Faktor; If Faktor = 1 Then Faktor := 3; Else Faktor := 1; End If; END LOOP; nPZ := MOD(nSum,10); nPZ := 10 - nPZ; If nPZ = 10 Then nPZ := 0; End If; return nPZ; end if; ------------- ##################################################################### ------------- Ende Modus P Prüfziffer ------------- ##################################################################### ------------- ##################################################################### ------------- START MODUS C25 ------------- ##################################################################### if in_modus = 'C25' then -- CODE 2/5 interleaved --DBMS_OUTPUT.PUT_LINE(' In Modus C25.'); ret_eancode := CHR(139); -- Startzeichen v_code_25 := LPAD(in_zahlencode,8,'0'); --DBMS_OUTPUT.PUT_LINE('v_code_25: '||v_code_25); v_count := 1; << schleife >> loop EXIT schleife when v_count > 7; c25_ts := SUBSTR(v_code_25,v_count,2); --DBMS_OUTPUT.PUT_LINE(' Teilstring'||v_count||' = '||c25_ts); v_zahl := TO_NUMBER(c25_ts); if v_zahl >= 0 and v_zahl <= 26 then ret_eancode := ret_eancode || CHR(v_zahl+100); -- Wandlung end if; if v_zahl = 27 then ret_eancode := ret_eancode || CHR(v_zahl+106); -- Wandlung end if; if v_zahl >= 28 and v_zahl <= 32 then ret_eancode := ret_eancode || CHR(v_zahl+100); -- Wandlung end if; if v_zahl >= 33 and v_zahl <= 99 then ret_eancode := ret_eancode || CHR(v_zahl); -- Wandlung end if; v_count := v_count + 2; END loop schleife; ret_eancode := ret_eancode || CHR(155); -- Endzeichen --DBMS_OUTPUT.PUT_LINE(' Länge EAN-CODE: '||LENGTH(ret_eancode)); --DBMS_OUTPUT.PUT_LINE(' EAN-CODE : '||ret_eancode); end if; -- ende if in_modus='C25' ------------- ##################################################################### ------------- STOP MODUS C25 ------------- ##################################################################### ------------- ##################################################################### ------------- START MODUS C13 ------------- ##################################################################### if in_modus = 'C13' then -- CODE EAN 13 --DBMS_OUTPUT.PUT_LINE(' In Modus C13.'); v_code_13 := LPAD(in_zahlencode,13,'0'); v_zahl := TO_NUMBER(SUBSTR(v_code_13,1,1)); --DBMS_OUTPUT.PUT_LINE('v_code_13 : '||v_code_13); --DBMS_OUTPUT.PUT_LINE('Vergleichsnummer : '||v_zahl); v_zahl := TO_NUMBER(SUBSTR(v_code_13,1,1)); -- #### CODE UMWANDLUNG #### ret_eancode := SUBSTR(v_code_13,1,1); -- code[1] ret_eancode := ret_eancode || ' '; -- Ruhezone ret_eancode := ret_eancode || '*'; -- Startzeichen ret_eancode := ret_eancode || SUBSTR(c13_absatz,TO_NUMBER(SUBSTR(v_code_13,2,1)+1),1); -- code[2] if v_zahl < 4 then ret_eancode := ret_eancode || SUBSTR(c13_absatz,TO_NUMBER(SUBSTR(v_code_13,3,1)+1),1); -- code[3] else ret_eancode := ret_eancode || SUBSTR(c13_absatz,TO_NUMBER(SUBSTR(v_code_13,3,1)+11),1); -- code[3] end if; if v_zahl = 0 OR v_zahl = 4 OR v_zahl = 7 OR v_zahl = 8 then ret_eancode := ret_eancode || SUBSTR(c13_absatz,TO_NUMBER(SUBSTR(v_code_13,4,1)+1),1); -- code[4] else ret_eancode := ret_eancode || SUBSTR(c13_absatz,TO_NUMBER(SUBSTR(v_code_13,4,1)+11),1); -- code[4] end if; if ( v_zahl > 1 AND v_zahl < 4) OR ( v_zahl > 5 AND v_zahl < 9) then ret_eancode := ret_eancode || SUBSTR(c13_absatz,TO_NUMBER(SUBSTR(v_code_13,5,1)+11),1); -- code[5] else ret_eancode := ret_eancode || SUBSTR(c13_absatz,TO_NUMBER(SUBSTR(v_code_13,5,1)+1),1); -- code[5] end if; --if v_zahl = 1 OR v_zahl = 2 OR v_zahl = 4 OR v_zahl > 7 then if v_zahl=0 or v_zahl = 1 OR v_zahl = 2 OR v_zahl = 5 or v_zahl = 7 then ret_eancode := ret_eancode || SUBSTR(c13_absatz,TO_NUMBER(SUBSTR(v_code_13,6,1)+1),1); -- code[6] else ret_eancode := ret_eancode || SUBSTR(c13_absatz,TO_NUMBER(SUBSTR(v_code_13,6,1)+11),1); -- code[6] end if; if v_zahl=0 or v_zahl = 3 OR v_zahl = 6 OR v_zahl > 7 then ret_eancode := ret_eancode || SUBSTR(c13_absatz,TO_NUMBER(SUBSTR(v_code_13,7,1)+1),1); -- code[7] else ret_eancode := ret_eancode || SUBSTR(c13_absatz,TO_NUMBER(SUBSTR(v_code_13,7,1)+11),1); -- code[7] end if; ret_eancode := ret_eancode || '#'; -- Trennzeichen ret_eancode := ret_eancode || SUBSTR(c13_csatz,TO_NUMBER(SUBSTR(v_code_13,8,1)+1),1); -- code[8] ret_eancode := ret_eancode || SUBSTR(c13_csatz,TO_NUMBER(SUBSTR(v_code_13,9,1)+1),1); -- code[9] ret_eancode := ret_eancode || SUBSTR(c13_csatz,TO_NUMBER(SUBSTR(v_code_13,10,1)+1),1); -- code[10] ret_eancode := ret_eancode || SUBSTR(c13_csatz,TO_NUMBER(SUBSTR(v_code_13,11,1)+1),1); -- code[11] ret_eancode := ret_eancode || SUBSTR(c13_csatz,TO_NUMBER(SUBSTR(v_code_13,12,1)+1),1); -- code[12] ret_eancode := ret_eancode || SUBSTR(c13_csatz,TO_NUMBER(SUBSTR(v_code_13,13,1)+1),1); -- code[13] ret_eancode := ret_eancode || '*'; -- Endezeichen --DBMS_OUTPUT.PUT_LINE(' Länge EAN-CODE: '||LENGTH(ret_eancode)); --DBMS_OUTPUT.PUT_LINE(' EAN-CODE : '||ret_eancode); end if; -- ende if in_modus='C13' ------------- ##################################################################### ------------- STOP MODUS C13 ------------- ##################################################################### ------------- ##################################################################### ------------- START MODUS C08 ------------- ##################################################################### if in_modus = 'C08' then -- CODE EAN 8 --DBMS_OUTPUT.PUT_LINE(' In Modus C08.'); v_code_8 := LPAD(in_zahlencode,8,'0'); v_zahl := TO_NUMBER(SUBSTR(v_code_8,1,1)); --DBMS_OUTPUT.PUT_LINE('v_code_8 : '||v_code_8); --DBMS_OUTPUT.PUT_LINE('Vergleichsnummer : '||v_zahl); v_zahl := TO_NUMBER(SUBSTR(v_code_8,1,1)); -- #### CODE UMWANDLUNG #### --ret_eancode := SUBSTR(v_code_8,1,1); -- code[1] ret_eancode := ret_eancode || '*'; -- Startzeichen ret_eancode := ret_eancode || ' '; -- Ruhezone ret_eancode := ret_eancode || SUBSTR(c13_absatz,TO_NUMBER(SUBSTR(v_code_8,1,1)+1),1); -- code[1] ret_eancode := ret_eancode || SUBSTR(c13_absatz,TO_NUMBER(SUBSTR(v_code_8,2,1)+1),1); -- code[2] if v_zahl = 0 OR v_zahl = 4 OR v_zahl = 7 OR v_zahl = 8 then ret_eancode := ret_eancode || SUBSTR(c13_absatz,TO_NUMBER(SUBSTR(v_code_8,3,1)+1),1); -- code[3] else ret_eancode := ret_eancode || SUBSTR(c13_absatz,TO_NUMBER(SUBSTR(v_code_8,3,1)+7),1); -- code[3] end if; if v_zahl = 0 OR v_zahl = 4 OR v_zahl = 7 OR v_zahl = 8 then ret_eancode := ret_eancode || SUBSTR(c13_absatz,TO_NUMBER(SUBSTR(v_code_8,4,1)+1),1); -- code[4] else ret_eancode := ret_eancode || SUBSTR(c13_absatz,TO_NUMBER(SUBSTR(v_code_8,4,1)+7),1); -- code[4] end if; ret_eancode := ret_eancode || '#'; ret_eancode := ret_eancode || SUBSTR(c13_csatz,TO_NUMBER(SUBSTR(v_code_8,5,1)+1),1); -- code[5] ret_eancode := ret_eancode || SUBSTR(c13_csatz,TO_NUMBER(SUBSTR(v_code_8,6,1)+1),1); -- code[6] ret_eancode := ret_eancode || SUBSTR(c13_csatz,TO_NUMBER(SUBSTR(v_code_8,7,1)+1),1); -- code[7] ret_eancode := ret_eancode || SUBSTR(c13_csatz,TO_NUMBER(SUBSTR(v_code_8,8,1)+1),1); -- code[8] ret_eancode := ret_eancode || '*'; -- Endezeichen --DBMS_OUTPUT.PUT_LINE(' Länge EAN-CODE: '||LENGTH(ret_eancode)); --DBMS_OUTPUT.PUT_LINE(' EAN-CODE : '||ret_eancode); end if; -- ende if in_modus='C13' ------------- ##################################################################### ------------- STOP MODUS C08 ------------- ##################################################################### else DBMS_OUTPUT.PUT_LINE('ZAHLENCODE: '||in_zahlencode||' NICHT NUMERISCH!!!'); ret_eancode := '-9'; end if; -- ende v_ret=0 return ret_eancode; EXCEPTION -- Fehler exits WHEN OTHERS THEN DBMS_OUTPUT.PUT_LINE('Fehler beim umwandeln ...'); l_fm := 'Pl/SQL Fehler: '||SQLCODE||' '||SUBSTR(SQLERRM,1,200); DBMS_OUTPUT.PUT_LINE(l_fm); DBMS_OUTPUT.PUT_LINE(' f_eancode am '||to_char(sysdate,'dd.mm.yyyy hh24:mi:ss')); return '-9'; END f_eancode;