Reputation: 613
I am writing a stored procedure to insert data into tbluser table. Following is my stored procedure:
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
I am getting error name MYSQL 1064: at the line DECLARE totalrows,current_id INT; saying mysql syntax is wrong.If I am omitting the first two statements in the stored procedure, then it works fine. Please correct me where am wrong, am new to using stored procedures in mysql
Upvotes: 1
Views: 337
Reputation: 93
Declare statements must be the first statement after the begin statement. The first select is throwing it off. see:http://dev.mysql.com/doc/refman/5.0/en/declare.html
Upvotes: 3