当我尝试使用此功能时,它总是失败。
DELIMITER $$
CREATE FUNCTION `f_hadir`(ID INT)
RETURNS INT
BEGIN
DECLARE TMP INT;
SELECT COUNT(ID_presensi_siswa) into TMP
FROM presensi_siswa
WHERE keterangan='Hadir' AND id_siswa=id LIMIT 1;
RETURN TMP;
END$$
DELIMITER ;
我有类似的代码,但它已成功创建。
DROP FUNCTION IF EXISTS `CategoriesToString`;
DELIMITER ;;
CREATE FUNCTION `CategoriesToString`(TID int) RETURNS varchar(500) CHARSET utf8
BEGIN
DECLARE result varchar(500);
SELECT group_concat(Category.Name) INTO result FROM Category
WHERE ID IN (SELECT CategoryID FROM TopicHasCategory WHERE TopicID = TID) LIMIT 1;
RETURN result;
END;;
DELIMITER ;
有人有想法吗?