错误代码1064 SQL

时间:2017-07-23 17:32:06

标签: mysql sql database oracle

我在MySQL中有一个触发器和一个过程有问题,练习曲目是:

定义一个触发器,自动删除患者,去年他们只进行了预先访问。

这是我创建的SQL代码:

CREATE TRIGGER EliminaVisitePreliminari
AFTER INSERT ON Visita
FOR EACH ROW
BEGIN
    IF(EXISTS(
        SELECT Vis.ID_Visita
        FROM Visita AS Vis, Preliminare AS Pre
        WHERE Vis.ID_Visita=Pre.ID_Visita
        AND DATEDIFF(CURRENT_DATE(), Vis.Data)>365
        GROUP BY Vis.ID_Visita)) THEN
            DELETE FROM Visita
            WHERE ID_Visita=(
                SELECT Vis.ID_Visita
                FROM Visita AS Vis1, Preliminare AS Pre1
                WHERE Vis1.ID_Visita=Pre1.ID_Visita
                AND DATEDIFF(CURRENT_DATE(), Vis.Data)>365
            ); # Error here
    END IF; # Here
END; # And here

这是程序:

定义一个计划程序,每个结束的月份自动计算每个月的干预量,显示尚未售出的百分比

从我创建的SQL:

CREATE PROCEDURE TotInterventiSettimanali(OUT Cont INT, SomTot INT, Saldare DECIMAL)
BEGIN
DECLARE Costo INT; # Error here
DECLARE DaSald DECIMAL; # Here
DECLARE Cont INT; # Here

SELECT COUNT(*), SUM(Vis.Parcella), AVG(Vis.Parcella) INTO Cont, SomTot, Saldare
FROM Visita AS Vis, Intervento AS Inerv
WHERE MONTH(Vis.Data)=MONTH(CURRENT_DATE())
AND Vis.ID_Visita=Interv.ID_Visita;

END; # And here

请帮帮我..非常感谢!

1 个答案:

答案 0 :(得分:0)

MySQL处理以“;”结尾的所有内容作为命令。要创建函数,过程和触发器,您必须将分隔符更改为其他内容,输入文本并更改分隔符。例如,在您的情况下:

DELIMITER //

CREATE PROCEDURE TotInterventiSettimanali(OUT Cont INT, SomTot INT, Saldare DECIMAL)
BEGIN
.......
END;
//
DELIMITER ;

请注意程序文本后的分隔符//