gpt4 book ai didi

mysql - From 在此位置无效,应为 : ';' in mysql

转载 作者:行者123 更新时间:2023-11-29 05:50:36 25 4
gpt4 key购买 nike

我正在学习如何在 MySQL 中创建存储过程,但在创建过程中出现错误。

这是我的存储过程:

CREATE DEFINER=`root`@`localhost` PROCEDURE `GetCategoryWiseProducts`(IN param varchar(250), IN isAll boolean)
BEGIN
declare catName VARCHAR(250) default '';
declare catId VARCHAR(250) default 0;

IF(isAll) THEN
SELECT 'All Products' as category_name, COUNT(*) as total from product_mast;
ELSE
SELECT category_name INTO catName, category_id INTO catId from category_mast WHERE slug = param;
SELECT catName as category_name, COUNT(*) as total from product_mast WHERE category_id = @category_id;
END IF;
END;

遇到错误

from is not valid at this position, expecting : ';'

在 else 语句的第一个查询中。

最佳答案

使用DELIMITER,参见24.1 Defining Stored Programs :

DELIMITER //

CREATE DEFINER ... PROCEDURE ...
BEGIN
...
-- SELECT category_name INTO catName, category_id INTO catId from category_mast WHERE slug = param;
SELECT category_name, category_id INTO catName, catId
from category_mast
WHERE slug = param;
...
END//

DELIMITER ;

@category_id 变量集的值在哪里?

关于mysql - From 在此位置无效,应为 : ';' in mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54732516/

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