我需要一个程序来验证数字是否为素数。语法似乎很好,但是得到以下错误:
查询:CREATE PROCEDURE prime_number(IN n INT)BEGIN SET @prime =“Prime number”; SET @n_prime =“非素数”; SET @divider = ...
错误代码:1064
您的SQL语法有错误;检查与MySQL服务器版本对应的手册,以便在第28行的''附近使用正确的语法
到目前为止,这是我的代码:
DELIMITER $
CREATE PROCEDURE prime_number(IN n INT)
BEGIN
SET @prime = "Prime number";
SET @n_prime = "Not prime number";
SET @divider = 0;
SET @i = 5;
IF n % 2 = 0 THEN
SELECT @n_prime;
ELSEIF (n < 2) OR ((n % 3) = 0) THEN /* Was using ELSE IF, separatedly*/
SELECT @n_prime;
ELSE
SET @root = SQRT(n);
WHILE @i <= @root && @divider = 0 DO
IF (n % @i) = 0 THEN
SET @divider = 1;
END IF;
SET @i = @i + 1;
END WHILE;
IF @divider = 1 THEN SELECT @n_prime;
ELSE SELECT @prime;
END IF;
END IF; /*Line 28*/
END $
DELIMITER ;
任何想法为什么会这样?