大家好,我被sql中的这个问题困住了:mysql总是在第4行给我语法错误,但我真的不知道它可能是什么

mhd8tkvw  于 2021-08-13  发布在  Java
关注(0)|答案(1)|浏览(327)

代码如下:

CREATE TRIGGER inserisci_richiesta_noID AFTER INSERT ON Richiesta
FOR EACH ROW
BEGIN    
    IF (NEW.ID_Cliente == NULL AND (NEW.Email NOT IN (SELECT Email FROM Utente))) THEN
        INSERT INTO Utente(ID, Nome, Cognome, Email, Telefono, ID_Livello_accesso)
        VALUES (NULL, 'Generato', 'Automaticamnete', NEW.Email, NEW.Telefono, 1);
        UPDATE Richiesta
        SET ID_Cliente = (SELECT ID FROM Cliente WHERE Email = :NEW.Email);
    ELSE NEW.ID_Cliente == NULL AND NEW.Email IN (SELECT Email FROM Utente;) THEN
        UPDATE Richiesta
        SET ID_Cliente = (SELECT ID FROM Cliente WHERE Email = NEW.Email);
    END IF;
END;

它给了我这个错误:
1064-您的sql语法有错误;请检查与您的mysql服务器版本对应的手册,以获得正确的语法,以便在“==null”附近使用(new.email not in(select email from utente)),然后在第4行的u'中插入

zyfwsgd6

zyfwsgd61#

这是密码

DELIMITER $$

CREATE TRIGGER inserisci_richiesta_noID AFTER INSERT ON Richiesta
FOR EACH ROW
BEGIN    
 IF (NEW.ID_Cliente IS NULL AND (NEW.Email NOT IN (SELECT Email FROM Utente))) THEN
    INSERT INTO Utente(ID, Nome, Cognome, Email, Telefono, ID_Livello_accesso)
    VALUES (NULL, 'Generato', 'Automaticamnete', NEW.Email, NEW.Telefono, 1)
    UPDATE Richiesta
    SET ID_Cliente = (SELECT ID FROM Cliente WHERE Email = NEW.Email);
ELSE IF (NEW.ID_Cliente IS NULL AND NEW.Email IN (SELECT Email FROM Utente)) THEN
    UPDATE Richiesta
    SET ID_Cliente = (SELECT ID FROM Cliente WHERE Email = NEW.Email);
END IF;
END$$

 DELIMITER ;

相关问题