1

Why the stored procedure can't be created?

delimiter //
CREATE PROCEDURE p()
BEGIN
DECLARE j INT;
SET j = 1;
SELECT j:=j+1, request.* FROM request;
END//

The problem is in line:

SET j:=j+1, ...
Aliaxander
  • 2,547
  • 4
  • 20
  • 45

1 Answers1

1

You need to add a @ to the variable name:

delimiter //
CREATE PROCEDURE p()
BEGIN
SET @j = 1;
SELECT @j:=@j+1, request.* FROM request;
END//

Here's an explanation: MySQL: @variable vs. variable. Whats the difference?

Community
  • 1
  • 1
Luis Alves
  • 1,286
  • 12
  • 32
  • So if i understand correctly, i can't change procedure-local variables this way? – Aliaxander Jan 19 '15 at 19:30
  • Yes, I think so. The problem is just in the increment you give inside the select, otherwise you could do SET j = 1; SET j = j +1; SELECT j, ... – Luis Alves Jan 19 '15 at 19:42