当前位置: 首页 > 知识库问答 >
问题:

错误mysql语法使用“declare pfee int default null;”,请检查与您的mysql服务器版本相对应的手册

安轶
2023-03-14
delimiter //
create procedure payFees(in deviceid int, in fee int)
begin
    declare pbalance int default null;
    declare ptype varchar(2) default "";
    declare total int;
    select balance, type into pbalance, ptype from device d where d.deviceid = deviceid;
    if pbalance is null
    then 
        select "cannot found the device" as result;
    else
/*      declare rate1 float;
        declare rate2 float;
        declare damage1 float;
        declare damage2 float;
        select rate1, rate2, damage1, damage2 into rate1, rate2, damage1, damage2 from charge_table ct where ct.type = ptype; */

        set total = pbalance + fee;
        update device d set balance = total where d.deviceid = deviceid;    

        declare pfee int default null;
        declare pdate varchar(6) default null;
        declare curl cursor for select basicfee, yearmonth from meter_record m, electricity_bill e where m.id = e.eid and m.deviceid = deviceid and flag = 0;
        declare continue handler for not found set pfee = null;
        open curl;

        fetch curl into pfee, pdate;
        while(pfee is not null) do
            declare overyear bool;
            if year(pdate) = year(now()) or (year(pdate) + 1 = year(now()) and month(pdate) = "12"):
            then
                set overyear = false;
            else
                set overyear = true;
            end if;
            select overyear;
            fetch curl into payfee, pdate;
        end while;
        close curl;
    end if;
end;
//

共有1个答案

公孙国兴
2023-03-14

您不能将您的声明放在其他语句之后。

https://dev.mysql.com/doc/refman/5.7/en/declare.html说:

DECLARE只允许在BEGIN...END复合语句中使用,并且必须在它的开始处,在任何其他语句之前。

 类似资料: