2024-01-15 11:31:03 +00:00
|
|
|
DELIMITER $$
|
2024-08-20 08:06:10 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`vn`@`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 ;
|