2024-01-15 11:31:03 +00:00
|
|
|
DELIMITER $$
|
2024-07-22 09:52:42 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`vn-admin`@`localhost` FUNCTION `vn`.`testNIF`(vNIF VARCHAR(9))
|
2024-01-15 11:31:03 +00:00
|
|
|
RETURNS tinyint(1)
|
|
|
|
DETERMINISTIC
|
|
|
|
BEGIN
|
|
|
|
|
|
|
|
DECLARE vIndice INT;
|
|
|
|
DECLARE vParteNumerica DECIMAL(8,0);
|
|
|
|
DECLARE vLetra VARCHAR(1);
|
|
|
|
DECLARE vLetrasPosibles VARCHAR(24) DEFAULT "TRWAGMYFPDXBNJZSQVHLCKE";
|
|
|
|
|
|
|
|
SET vLetra = SUBSTRING(vNIF, 9, 1);
|
|
|
|
|
|
|
|
SET vParteNumerica = CAST(SUBSTRING(vNIF, 1, 8) AS DECIMAL(8,0));
|
|
|
|
|
|
|
|
SET vIndice = Round(vParteNumerica MOD 23, 0) + 1;
|
|
|
|
|
|
|
|
If SUBSTRING(vLetrasPosibles, vIndice, 1) = vLetra Then
|
|
|
|
|
|
|
|
RETURN TRUE;
|
|
|
|
|
|
|
|
ELSE
|
|
|
|
|
|
|
|
RETURN FALSE;
|
|
|
|
|
|
|
|
END IF;
|
|
|
|
|
|
|
|
END$$
|
|
|
|
DELIMITER ;
|