Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Función PLSQL que permite calcular el dígito verificador de un código de barras EAN13.
CREATE OR REPLACE FUNCTION CODIGO_BARRAS_GENERAR_DV(P_CODIGO IN VARCHAR2, P_TIPO VARCHAR2 DEFAULT 'EAN13') RETURN VARCHAR2 IS
L_SUM NUMBER;
L_MULTIPLE NUMBER;
V_CODIGO_EAN13 VARCHAR2(13) DEFAULT NULL;
BEGIN
IF (P_TIPO = 'EAN13') THEN
V_CODIGO_EAN13 := SUBSTR(LPAD(P_CODIGO,12,'0'),1,12);
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(V_CODIGO_EAN13, I, 1) * L_MULTIPLE;
END LOOP;
RETURN V_CODIGO_EAN13||REPLACE((10 - MOD(L_SUM, 10)),10,0);
ELSE
RETURN NULL;
END IF;
END;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.