MySQL语法检查

问题描述 投票:0回答:2

我有以下脚本,它给我一个语法错误,我检查了一切,但无法找出什么是错的。感谢您对此问题的任何帮助,请查看下面的脚本。关心纳德

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;

enter image description here

mysql
2个回答
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 ;

0
投票

只需更改脚本的结尾,如下所示:

END 
DELIMITER $$;
© www.soinside.com 2019 - 2024. All rights reserved.