Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
mysql触发器和更新中出错_Mysql_Variables_If Statement_Triggers - Fatal编程技术网

mysql触发器和更新中出错

mysql触发器和更新中出错,mysql,variables,if-statement,triggers,Mysql,Variables,If Statement,Triggers,我有下一个触发器: CREATE TRIGGER t_call_status AFTER INSERT ON tblcdr FOR EACH ROW BEGIN DECLARE lastid integer; DECLARE nseg integer; SET lastid = LAST_INSERT_ID(); SET nseg = 120; IF ((origen = 'ANSWERED' &

我有下一个触发器:

CREATE
    TRIGGER t_call_status 
    AFTER INSERT 
    ON tblcdr FOR EACH ROW 
BEGIN
    
    DECLARE lastid integer;
    DECLARE nseg integer;
    
    SET lastid = LAST_INSERT_ID();
    SET nseg = 120;

    IF ((origen = 'ANSWERED' && destino = 'ANSWERED') && (billsec_origen >= nseg && disposition_destino >= nseg)) THEN
        update tblcdr set call_status = 3 where id = lastid;
    ELSE IF (origen = 'ANSWERED' && destino = 'ANSWERED') THEN
        update tblcdr set call_status = 2 where id = lastid;
    ELSE IF (origen = 'ANSWERED' && destino <> 'ANSWERED') THEN
        update tblcdr set call_status = 1 where id = lastid;
    ELSE IF (origen <> 'ANSWERED' && destino <> 'ANSWERED') THEN
        update tblcdr set call_status = 0 where id = lastid;
    ELSE
        update tblcdr set call_status = 0 where id = lastid;
    END IF;

END;
创建
触发呼叫状态
插入后
关于每行的tblcdr
开始
声明lastid整数;
声明nseg整数;
SET lastid=LAST_INSERT_ID();
设置nseg=120;
如果((origen='Answeed'&&destino='Answeed')&(billsec_origen>=nseg&&disposition_destino>=nseg)),则
更新tblcdr set call_status=3,其中id=lastid;
否则,如果(origen='responsed'&&destino='responsed'),则
更新tblcdr set call_status=2,其中id=lastid;
否则,如果(origen=‘已回答’&&destino‘已回答’),则
更新tblcdr set call_status=1,其中id=lastid;
否则如果(origen“已回答”和destino“已回答”),则
更新tblcdr set call_status=0,其中id=lastid;
其他的
更新tblcdr set call_status=0,其中id=lastid;
如果结束;
结束;
但是,我得到了下一个错误:

1064-您的SQL语法有错误;检查与您的MySQL服务器版本对应的手册,以了解要使用的正确语法 在第7行的“”附近

我怎样才能修好它


问候。

第一个问题是,不能在插入后触发器中更新触发器运行的同一个表。在使用before insert触发器插入数据之前,需要修改数据。这不会导致您的语法错误,但它会很快出现在您使用的MySQL客户端上?大多数情况下都需要设置语句分隔符,以在
end
之后结束触发器的创建,尽管执行此操作的方法有所不同。我使用的是phpmyadmin.pala uuu您是对的,当INSERT触发器触发时,我无法更改表。插入可能会执行一些锁定,这可能会导致死锁。此外,从触发器更新表将导致在无限递归循环中再次触发相同的触发器。这两个原因都是MySQL阻止您这样做的原因。