salix/db/routines/vn/procedures/vehicle_checkNumberPlate.sql

31 lines
792 B
MySQL
Raw Normal View History

DELIMITER $$
2025-01-20 13:43:14 +00:00
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`vehicle_checkNumberPlate`(
vNumberPlate VARCHAR(10),
vCountryCodeFk VARCHAR(2)
)
BEGIN
/**
2025-01-20 13:43:14 +00:00
* Comprueba si la matricula pasada tiene el formato
* correcto dependiendo del pais del vehiculo.
*
* @param vNumberPlate Número de matricula
* @param vCountryCodeFk Código de pais
*/
DECLARE vRegex VARCHAR(45);
2025-01-20 13:43:14 +00:00
IF vCountryCodeFk IS NULL THEN
SET vRegex = '^[A-Z0-9 -]{6,12}$';
ELSE
SELECT regex INTO vRegex
FROM vehiclePlateRegex
WHERE countryCodeFk = vCountryCodeFk;
END IF;
IF NOT vNumberPlate REGEXP BINARY (vRegex)THEN
2025-01-20 13:43:14 +00:00
CALL util.throw(CONCAT('La matricula ', vNumberPlate,
' no es valida', IF(vCountryCodeFk IS NOT NULL,
CONCAT(' para ', vCountryCodeFk), '')));
END IF;
END$$
DELIMITER ;