这是我的触发器
CREATE TRIGGER `proximo_pago` BEFORE INSERT ON `pago`
FOR EACH ROW BEGIN
declare num_orden integer;
select max(orden) from pago where lote=NEW.lote into num_orden;
if(num_orden is NULL)
then
set NEW.orden=1;
else
set NEW.orden=num_orden+1;
end if;
END
和错误
SQL查询:
CREATE TRIGGER `proximo_pago` BEFORE INSERT ON `pago`
FOR EACH ROW BEGIN
declare num_orden integer;
MySQL说:文档
我尝试使用DELIMITER,但它不起作用,请帮帮我,谢谢
答案 0 :(得分:0)
我的答案仅仅基于你的问题的必要性,即变量的声明..如果Delimiter没有做到这一点,可能是你的语法错误,因为你没有在变量中设置SELECT查询。先试试这个。
DELIMITER $$
CREATE
TRIGGER `proximo_pago` BEFORE INSERT
on `pago`
FOR EACH ROW
BEGIN
DECLARE num_orden int;
SET num_orden = select max(orden) from pago where lote=NEW.lote;
if(num_orden is NULL)
then
set NEW.orden=1;
else
set NEW.orden=num_orden+1;
end if;
END$$
DELIMITER ;