此代码在@counter上产生错误 错误代码显示“语法错误:意外'@counter'(文本后缀)”
我无法找到让它运行的方法,
以下是代码:
CREATE DEFINER=`root`@`localhost` PROCEDURE ValidateCC(IN ccNum char(16), OUT isValid BOOLEAN )
BEGIN
DECLARE @counter, @sum, @numb, @tmp AS INT DEFAULT 0;
DECLARE @result TINYINT(1) DEFAULT 1;
SET isValid = ‘False’;
IF ccNum IS NULL THEN
SET @result = 0;
ELSEIF char_length(ccNum) < 12 THEN
SET @result = 0;
SET @counter = char_length(ccNum);
IF ccNum NOT_REGEXP '^[0-9]+$' THEN
SET @result = 0;
END IF;
WHILE @counter > 0 DO
IF @counter > 1 THEN
SET @tmp = (ASCII(SUBSTR(ccNum, @counter, 1)) - 48) * 2;
IF @tmp > 9 THEN
SET @sum = @sum + @tmp - 9;
ELSE
SET @sum = @sum + @tmp;
END IF;
SET @number = @number + (ASCII(SUBSTR(ccNum, @counter, 1)) -48);
SET @counter = @counter - 2;
END IF;
SET @sum = MOD((@sum + @number), 10);
IF @sum = 0 THEN
SET @result =1
END IF;
END WHILE;
IF @result = 1 THEN
SET isValid = ‘True’;
ELSE
SET isValid = ‘False’;
END IF;
END ;
答案 0 :(得分:0)
在存储过程中使用正确的语法来声明变量(http://dev.mysql.com/doc/refman/5.0/en/declare-local-variable.html):
`DECLARE counter, sum, numb, tmp INT DEFAULT 0;`
而不是DECLARE @counter, @sum, @numb, @tmp AS INT DEFAULT 0;
...没有@
,AS