我在 mysql 中创建了一个触发器,它没有编译错误,但没有执行其中提出的任何操作,与调用的不一样。以下代码。
DELIMITER
//
DROP TRIGGER BILHETAGEM_ACERTOS//
CREATE TRIGGER BILHETAGEM_ACERTOS
BEFORE INSERT ON bilhetagem FOR EACH ROW
BEGIN
SET new.bil_canal = LEFT(new.bil_canal,locate('-',new.bil_canal)-1);
SET @plano = 0;
SET @tarifa = 0;
SET @placa = 0;
SET @seq = 0;
SET @canal = 0;
SET @tronco = 0;
SET @troncoplaca = 0;
SET new.bil_gravacao = SUBSTRING(new.bil_gravacao,7);
SELECT SUBSTRING(new.bil_canal, 1, (LOCATE('/', new.bil_canal) -1)) INTO @placa;
IF (@placa = 'Khomp') THEN
SET @canal = RIGHT(new.bil_canal,LENGTH(new.bil_canal) - LOCATE('/', new.bil_canal));
SET @seq = LEFT(@canal, LOCATE('C', @canal) -1);
IF (LOCATE('-', @canal) > 0) THEN
SET @canal = LEFT(@canal, LOCATE('-', @canal) -1);
END IF;
SET @canal = RIGHT(@canal,(LENGTH(@canal) - LOCATE('C', @canal)));
SELECT tro_codigo INTO @tronco FROM troncos_placas where tropla_placa = @seq LIMIT 1;
SELECT tro_placa INTO @tipo FROM troncos where tro_codigo = @tronco LIMIT 1;
SELECT tro_nome INTO @tronco_nome FROM troncos where tro_codigo = @tronco LIMIT 1;
IF (@tipo = 'E1') THEN
SELECT tropla_codigo INTO @troncoplaca FROM troncos_placas where tro_codigo = @tronco LIMIT 1;
ELSE
SELECT tro_codigo INTO @tronco FROM troncos_placas where tropla_placa = @seq and tropla_codigo = @canal LIMIT 1;
SET @troncoplaca = @canal;
END IF;
ELSE
SELECT SUBSTRING(new.bil_canal, (LOCATE('/', new.bil_canal) +1)) INTO @canal;
SELECT tro_codigo INTO @tronco FROM troncos where tro_tipo = @placa and tro_apelido = @canal LIMIT 1;
SET @troncoplaca = 0;
END IF;
IF (LOCATE('B', new.ram_codigo)) THEN
SET new.ram_codigo = @tronco_nome;
END IF;
IF (LOCATE('GATW', new.ram_codigo)) THEN
SET new.ram_codigo = @tronco_nome;
END IF;
SET new.tro_codigo = @tronco;
SET new.tropla_codigo = @troncoplaca;
SELECT pla_codigo INTO @plano FROM ramal where ram_codigo = new.ram_codigo LIMIT 1;
IF @plano > 0 THEN
IF ((LEFT(new.bil_destino,1) > 0) and (LEFT(new.bil_destino,1) <= 5)) THEN
SELECT pla_vlrminutolocalfixo INTO @tarifa FROM planos where pla_codigo = @plano LIMIT 1;
ELSE
IF ((LEFT(new.bil_destino,1) > 5) and (LEFT(new.bil_destino,1) <= 9)) THEN
SELECT pla_vlrminutolocalcelular INTO @tarifa FROM planos where pla_codigo = @plano LIMIT 1;
ELSE
IF (LEFT(new.bil_destino,4) <> '0800') THEN
IF ((SUBSTRING(new.bil_destino,2,1) < 2) and (SUBSTRING(new.bil_destino,4,1) <= 5)) THEN
SELECT pla_vlrminutodddfixo_deestado INTO @tarifa FROM planos where pla_codigo = @plano LIMIT 1;
ELSE
SELECT pla_vlrminutodddfixo_foestado INTO @tarifa FROM planos where pla_codigo = @plano LIMIT 1;
END IF;
END IF;
END IF;
END IF;
END IF;
END IF;
SET new.pla_codigo = @plano;
SELECT pla_tempo INTO @tempo FROM planos where pla_codigo = @plano LIMIT 1;
SELECT pla_cadencia INTO @cadencia FROM planos where pla_codigo = @plano LIMIT 1;
SET new.pla_tempo = @tempo;
SET new.pla_cadencia = @cadencia;
SET new.bil_tarifabase = @tarifa;
SET new.bil_tarifado = 'S';
SET @relseg = new.bil_duracao;
SET @reldata = DATE(new.bil_dataligacao);
IF ((LENGTH(new.bil_destino) > 4) AND (new.bil_duracao > 0) AND (new.bil_entradasaida <> 'E')) THEN
IF (new.bil_duracao <= @tempo) THEN
SET new.bil_vlrvenda = (@tarifa / 60) * @tempo;
ELSE
SET @valor = (@tarifa / 60) * @cadencia;
SET @tmp = (new.bil_duracao - @tempo);
SET @qtd = 1;
WHILE @tmp > 0 DO
SET @tmp = (@tmp - @cadencia);
SET @qtd = @qtd + 1;
END WHILE;
SET new.bil_vlrvenda = @tarifa + (@valor * @qtd);
END IF;
END IF;
IF (@tronco > 0) THEN
SELECT reltro_segundos INTO @segundos from relatorio_troncos where tro_codigo = @tronco and reltro_dataligacao = @reldata limit 1;
IF ((@segundos > 0) or (@segundos is not null)) THEN
UPDATE relatorio_troncos SET reltro_segundos = (@segundos + @relseg) WHERE tro_codigo = @tronco and reltro_dataligacao = new.bil_dataligacao;
ELSE
INSERT INTO relatorio_troncos (tro_codigo, reltro_dataligacao, reltro_segundos) values (@tronco, @reldata, @relseg);
END IF;
END IF;
END IF;
END//
DELIMITER ;``