创建函数时MYSQL错误

时间:2014-09-24 09:17:04

标签: mysql function

我有一个功能

DELIMITER $$

CREATE FUNCTION `GetSuppliedMedicineQuantity` (FromDate varchar(50),Phid int,Todate varchar(50), MId INT)
RETURNS INTEGER
BEGIN

DECLARE totalmedicinecount INT;
IF(Todate is null)
then
    select totalmedicinecount=sum(Totalquantity+FreeMedQuantity) from suppliedmedicine where  
    DATE(DateOfSupply)>=DATE(FromDate)
    and Pharmacyid=phid and Medicineid=MId
    group by Medicineid;

else
    select totalmedicinecount=sum(Totalquantity+FreeMedQuantity) from suppliedmedicine where  
    DATE(DateOfSupply)<DATE(FromDate) and DATE(dateofsupply)<DATE(Todate)
    and Pharmacyid=phid and Medicineid=MId
    group by Medicineid;
end if;

SET totalmedicinecount=IF(ISNULL(totalmedicinecount),0,totalmedicinecount);

RETURN totalmedicinecount;
END$$

创建函数时出现错误:

ERROR 1415: Not allowed to return a result set from a function

我是MYSQL的新手,不知道如何解决这个问题,请帮忙。提前谢谢。

0 个答案:

没有答案