第二次在 mysql 存储过程中获取行数时出错

Error while getting the row count in mysql stored procedure for second time

我正在编写一个存储过程来将数据插入到 tbluser table。以下是我的存储过程:

BEGIN

  /* Check if user already exits*/
  DECLARE user_count INT;
  select count(*) from tblusers into user_count where name = 'joseph';  

  /* Calculate the row count of table and calculate the id for new row*/
  DECLARE totalrows,current_id INT;
  select count(*) from tblusers into totalrows; 
  SET current_id = totalrows + 1;

 /*Other part of procedure with insert statement*/

END

我收到错误名称 MYSQL 1064:在 DECLARE totalrows 行,current_id INT;说 mysql 语法是 wrong.If 我省略了存储过程中的前两个语句,然后它工作正常。请纠正我错误的地方,我是 mysql

中使用存储过程的新手

声明语句必须是开始语句之后的第一条语句。第一个 select 放弃了。见:http://dev.mysql.com/doc/refman/5.0/en/declare.html