Tengo un problema con un trigger en MySql. A la hora de realizar un registro, se queda cargando y no pasa de ahí, ni se puede detener tampoco, a menos que detenga el servidor.
CREATE TRIGGER `GENERAR_SERIE_CORRELATIVO` AFTER INSERT ON `detalle_matricula_pagos`
FOR EACH ROW BEGIN
Declare serie integer;
Declare consecutivo integer;
Declare codigo varchar(14);
Declare valor varchar(6);
Declare id integer;
set id = (select MAX(IdDetalleMatriculasPago) from Detalle_Matricula_Pagos ORDER BY IdDetalleMatriculasPago DESC LIMIT 1 );
Set serie = id / 1000000 + 1;
Set consecutivo = id % 1000000 + Case serie When 1 Then 0 Else 1 End;
Set valor = Cast(serie As varchar(6));
While (length(valor) < 4) do
Set valor = '0' + valor;
end while;
Set codigo = valor;
Set valor = Cast(consecutivo As varchar(6));
While (length (valor) < 6) do
Set valor = '0' + valor;
end while;
UPDATE Detalle_Matricula_Pagos SET NEW.CODIGO = CONCAT_WS('-', codigo ,valor)
WHERE IdDetalleMatriculasPago= id;
end