Stack Exchange
From is not valid at this position, expecting : ';' in mysql
I am learning how to create a stored procedure in MySQL and I am getting an error while creating it.
Here is my stored procedure:
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;

Getting an error

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

in else statement's first query.

Use DELIMITER, see 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 ;

Where is the value of the @category_id variable set?.

Select into syntax is SELECT id, data INTO @x, @y FROM test.t1 LIMIT 1; see https://dev.mysql.com/doc/refman/8.0/en/select-into.html
