我有以下脚本给了我一个语法错误,并且我检查了所有内容,但找不到错误所在。 感谢您在此问题上的任何帮助,请在下面找到脚本。 问候纳德
DROP PROCEDURE IF EXISTS CalcDoseCount;
DELIMITER $$
create FUNCTION CalcDoseCount (DivType Int, DivDose varchar(300), DurationType float, Duration float, EveryType float, Every float,OrderType int)
RETURNS Int
BEGIN
Declare SingleDose int;
Declare TotalDuration int;
Declare DivEvery int;
Declare DoseCount float;
set TotalDuration = Duration * case DurationType when 0 then 1 when 1 then 7 when 2 then 30 end;
begin
if DivType in (0,2,3) then
if EveryType = 0 then -- every type is hours
set DoseCount = CEILING( TotalDuration * 24 / Every);
else if EveryType = 1 then-- every type is days
set DoseCount = CEILING(TotalDuration / Every );
else if EveryType = 2 then-- every type is weeks
set DoseCount = CEILING(TotalDuration / ( Every * 7));
else if EveryType = 3 then-- every type is times
set DoseCount = TotalDuration * Every;
else if EveryType = 4 then-- every type is times per week
set DoseCount = CEILING( TotalDuration / 7 ) * Every;
end if;
end if;
If DivType = 1 then
set DivEvery = right(DivDose,1);
if DivEvery = 0 then
set DivEvery = 1;
end if;
set DoseCount = (CEILING(TotalDuration / DivEvery));
end if;
if isnull(DoseCount) then
set DoseCount = 1;
end if;
if DoseCount = 0 then
set DoseCount = 1;
end if;
return DoseCount ;
END $$
DELIMITER;
答案 0 :(得分:0)
只需更改脚本结尾,如下所示:
END
DELIMITER $$;
答案 1 :(得分:0)
2个问题,1-您有一个备用的开头,应将其删除,2否则应为elseif。
DROP function IF EXISTS CalcDoseCount;
DELIMITER $$
create FUNCTION CalcDoseCount (DivType Int, DivDose varchar(300), DurationType float, Duration float, EveryType float, Every float,OrderType int)
RETURNS Int
BEGIN
Declare SingleDose int;
Declare TotalDuration int;
Declare DivEvery int;
Declare DoseCount float;
set TotalDuration = Duration * case DurationType when 0 then 1 when 1 then 7 when 2 then 30 end;
#begin
if DivType in (0,2,3) then
if EveryType = 0 then -- every type is hours
set DoseCount = CEILING( TotalDuration * 24 / Every);
elseif EveryType = 1 then-- every type is days
set DoseCount = CEILING(TotalDuration / Every );
elseif EveryType = 2 then-- every type is weeks
set DoseCount = CEILING(TotalDuration / ( Every * 7));
elseif EveryType = 3 then-- every type is times
set DoseCount = TotalDuration * Every;
elseif EveryType = 4 then-- every type is times per week
set DoseCount = CEILING( TotalDuration / 7 ) * Every;
end if;
end if;
If DivType = 1 then
set DivEvery = right(DivDose,1);
if DivEvery = 0 then
set DivEvery = 1;
end if;
set DoseCount = (CEILING(TotalDuration / DivEvery));
end if;
if isnull(DoseCount) then
set DoseCount = 1;
end if;
if DoseCount = 0 then
set DoseCount = 1;
end if;
return DoseCount ;
END $$
DELIMITER ;