create function fine1(date1 date,date2 date) returns int
-> begin
-> declare fine int;
-> if datediff(date1,date2)>10 then
-> set fine=(datediff-10)*5;
-> return fine;
-> end;
-> //

我写了这段代码,但它给了我一个错误。

最佳答案

你好像失踪了END IF

  create function fine1(date1 date,date2 date) returns int
-> begin
-> declare fine int;
-> if datediff(date1,date2)>10 then
-> set fine=(datediff(date1,date2)-10)*5; <-- was not correct.
-> end if;  <-- was missing
-> return fine;
-> end;

此外,似乎您正在使用datediff函数进行计算,而您错过了传递参数。
set fine=(datediff-10)*5;

应该是
set fine=(datediff(date1,date2)-10)*5;

09-17 20:44