CREATE DEFINER=`root`@`localhost` PROCEDURE `GetStateList`(IN _CountryName VARCHAR(255))
BEGIN
    DECLARE @CCode VARCHAR(50)
SET @CCode = (SELECT CountryID  from countrylist where CountryName = _CountryName);
  SELECT @CCode;

END

最佳答案

您需要将分隔符重新定义为$$以外的其他名称(例如:;)。最后,将限制器重置回;。另外,在Declare语句中缺少分号:

DELIMITER $$

CREATE DEFINER=`root`@`localhost` PROCEDURE `GetStateList`(IN _CountryName VARCHAR(255))

BEGIN
    DECLARE @CCode VARCHAR(50); -- semicolon was missing here
    SET @CCode = (SELECT CountryID
                  from countrylist
                  where CountryName = _CountryName);

    SELECT @CCode;

END$$

DELIMITER ;

09-06 15:26