简体   繁体   中英

MySQL stored procedure to return table

I'm trying to create a stored procedure to return data from a table. I'm using MySQL. this is the code:

CREATE DEFINER=`imswms`@`10.0.90.%` FUNCTION `sp_daily_numbers_by_man_and_prod`(`man` VARCHAR(100), `startDate` DATETIME, `endDate` DATETIME)
RETURNS SET
LANGUAGE SQL
NOT DETERMINISTIC
READS SQL DATA
SQL SECURITY DEFINER
COMMENT ''
BEGIN
select * from dailynumbersdetails 
 where dailynumbersdetails.PostDate >= startDate 
    and dailynumbersdetails.PostDate < endDate 
    and dailynumbersdetails.Manufacturer = man 
    group by dailynumbersdetails.PartNumber;
END

But when trying to save the procedure I get the following error:

SQL Error (1064): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LANGUAGE SQL NOT DETERMINISTIC READS SQL DATA SQL SECURITY DEFINER COMME' at line 3

What could be wrong ?

The syntax was incorrect. You created a FUNCTION, but needed to create a PROCEDURE that returns result set. Try this code -

CREATE DEFINER = 'imswms'@'10.0.90.%'
PROCEDURE `sp_daily_numbers_by_man_and_prod` (`man` VARCHAR(100), `startDate` DATETIME, `endDate` DATETIME)
SQL SECURITY DEFINER
COMMENT ''
BEGIN
  SELECT * FROM dailynumbersdetails
  WHERE dailynumbersdetails.PostDate >= startDate
  AND dailynumbersdetails.PostDate < endDate
  AND dailynumbersdetails.Manufacturer = man
  GROUP BY dailynumbersdetails.PartNumber;
END

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM