我尝试编写MySql函数来返回一个节点的子计数,并且我写了这段代码
CREATE DEFINER=`root`@`localhost` FUNCTION `get_child_count`(`id` INT) RETURNS int(11)
READS SQL DATA
Begin
declare temp int(11);
SELECT count(*) into temp FROM tbl_photo_album where parent_id = id;
return temp;
End
每当我试图运行这个功能时,它什么都没有。
答案 0 :(得分:0)
select ... into...
,试试这个:
set temp = (select count(*) from tbl_photo_album where parent_id = id);
答案 1 :(得分:0)
尝试这个。
DELIMITER $$
CREATE DEFINER=`root`@`localhost` FUNCTION `get_child_count`(`id` INT) RETURNS int(11)
READS SQL DATA
Begin
declare temp int(11);
SELECT count(*) into temp FROM tbl_photo_album where parent_id = id;
return temp;
END$$
DELIMITER ;
select get_child_count(10); -- Pass Id for what you want result.