Israeli Identity Card Valiadation
Needed to check the validity of an Israeli identity card number
I created this simple function
http://goo.gl/z2roI
http://goo.gl/dCbS0
I created this simple function
CREATE OR REPLACE FUNCTION checkid (id_number IN VARCHAR2)references:
RETURN VARCHAR2
IS
fixed_number VARCHAR2 (10);
digit NUMBER := 0;
sum_digits NUMBER := 0;
BEGIN
CASE
WHEN LENGTH (id_number) < 9 THEN fixed_number := LPAD (id_number, 9, '0'); WHEN LENGTH (id_number) > 9
THEN
RETURN 'Too Long';
ELSE
fixed_number := id_number;
END CASE;
FOR i IN 1 .. 9
LOOP
digit :=
TO_NUMBER (SUBSTR (fixed_number, i, 1))
* (CASE WHEN MOD (i, 2) = 0 THEN 2 ELSE 1 END);
IF LENGTH (digit) > 1
THEN
digit := SUBSTR (digit, 1, 1) + SUBSTR (digit, 2, 1);
END IF;
DBMS_OUTPUT.put_line (i || '#');
sum_digits := sum_digits + digit;
IF MOD (sum_digits, 10) = 0
THEN
RETURN 'OK';
ELSE
RETURN 'BAD';
END IF;
END LOOP;
RETURN TO_CHAR (sum_digits);
END;
/
http://goo.gl/z2roI
http://goo.gl/dCbS0
Comments
Post a Comment