Created
September 25, 2014 00:39
-
-
Save NekoTashi/05a4a8e0967a3d97378d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DECLARE | |
TYPE t_number_list IS varray(12) of INTEGER; | |
v_rut t_number_list := t_number_list(1, 7, 1, 2, 3, 5, 9, 9); | |
v_dig_ver INTEGER; | |
FUNCTION fn_digito_verificador(p_rut IN t_number_list) | |
RETURN INTEGER | |
IS | |
p_dig_ver INTEGER; | |
TYPE t_number_list IS varray(12) of INTEGER; | |
v_serie t_number_list := t_number_list(3, 2, 7, 6, 5, 4, 3, 2); | |
v_suma INTEGER := 0; | |
v_mod INTEGER; | |
v_result VARCHAR2(10); | |
BEGIN | |
FOR i IN 1.. v_rut.count LOOP | |
v_suma := p_rut(i) * v_serie(i) + v_suma; | |
END LOOP; | |
v_mod := MOD(v_suma, 11); | |
v_result := 11 - v_mod; | |
p_dig_ver := to_char(v_result); | |
IF p_dig_ver = '11' THEN | |
RETURN '0'; | |
ELSIF p_dig_ver = '10' THEN | |
RETURN 'K'; | |
END IF; | |
RETURN p_dig_ver; | |
END fn_digito_verificador; | |
BEGIN | |
v_dig_ver := fn_digito_verificador(v_rut); | |
DBMS_OUTPUT.PUT_LINE(v_dig_ver); | |
END; | |
/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment