gpt4 book ai didi

mysql - 在 PhpMyAdmin 中调用存储过程是可以的,但作为查询运行不起作用

转载 作者:可可西里 更新时间:2023-11-01 08:40:13 26 4
gpt4 key购买 nike

这是我在 mysql 中的存储过程。当我在 phpmyadmin 中调用它时,一切正常
调用 phpmyadmin
CALL sp_del_temp_record('tbl_user_login_and',1880,10)但是当我在 mysql_query 中使用时它不起作用:
mysql_query("CALL sp_del_temp_record('tbl_user_login_and',1877,10)");
这是我的 sp:

CREATE PROCEDURE `sp_del_temp_record`(p_tbl varchar(255),  max_record smallint(6),del_count smallint(6))
BEGIN
SET @count_query=CONCAT ("select count(auto_id) into @count_record from ",p_tbl);
PREPARE count_record_q FROM @count_query;
EXECUTE count_record_q;


if @count_record>max_record then
SET @del_query=CONCAT ("delete from ",p_tbl," order by auto_id asc limit ",del_count);
PREPARE del_query_q FROM @del_query;
EXECUTE del_query_q;
end if;
END;

最佳答案

尝试这种方式:

DELIMITER $$
CREATE PROCEDURE `sp_del_temp_record`(p_tbl varchar(255), max_record smallint(6),del_count smallint(6))
BEGIN
SET count_query=CONCAT ("select count(auto_id) into count_record from ",p_tbl);
PREPARE count_record_q FROM count_query;
EXECUTE count_record_q;


if count_record>max_record then
SET del_query=CONCAT ("delete from ",p_tbl," order by auto_id asc limit ",del_count);
PREPARE del_query_q FROM del_query;
EXECUTE del_query_q;
end if;
END$$

DELIMITER ;

关于mysql - 在 PhpMyAdmin 中调用存储过程是可以的,但作为查询运行不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34411135/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com