日期:2014-05-16  浏览次数:20954 次

mysql中存储过程报错问题
我的mysql版本是5.5的,然后写了个测试存储过程,运行时报错,麻烦看看那里错了,这个代码:
SQL code

DROP PROCEDURE IF EXISTS `sptest`;

CREATE PROCEDURE `sptest`()
BEGIN
DECLARE @id int(11)NOT NULL;
SELECT @id INTO ContractID FROM contractinfo WHERE SymbolNum='al1105';
SELECT * FROM contractinfo WHERE ContractID=@id;
END;


报这个错误:
[Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@id int(11)' at line 4
请高手看看,到底错在哪里。

------解决方案--------------------
声明变量的时候错了!
------解决方案--------------------
CREATE PROCEDURE `sptest`()
BEGIN
DECLARE id1 int(11)NOT NULL;
SELECT ContractID into id1 FROM contractinfo WHERE SymbolNum='al1105';
SELECT * FROM contractinfo WHERE ContractID=@id1;
END;
------解决方案--------------------
SQL code

CREATE PROCEDURE `sptest`()
BEGIN
DECLARE id1 int(11);  --not null不能定义
SELECT ContractID into id1 FROM contractinfo WHERE SymbolNum='al1105';
SELECT * FROM contractinfo WHERE ContractID=id1;
END;

------解决方案--------------------
CREATE PROCEDURE `sptest`()
BEGIN
DECLARE id1 int(11)NOT NULL;
SELECT ContractID into id1 FROM contractinfo WHERE SymbolNum='al1105';
SELECT * FROM contractinfo WHERE ContractID=id1;
END;