1

I tried to run this SQL statement in MySQL 5.5 and 5.7.1 but always got error.

DELIMITER //
CREATE PROCEDURE one_off_update_user_info_view_type()
  BEGIN
    DECLARE @batchsize BIGINT DEFAULT 1;
  END
//

enter image description here

You could check the script in local MySQL 5.5+ since it does not contain any business logic or inner-company databases. Could anyone tell me why the error arose and how to fix it?

3

You use DECLARE in compound-statement syntax to declare a local variable, cursor, condition or handler. However, your variable @batchsize is a session global variable due to the presence of the @ prefix, and it is an error to attempt to redeclare a global variable.

Change the name of your variable from @batchsize to batchsize, and then read up on MySQL variables.

| improve this answer | |
1

You cannot use @variable_name to declare variable. @ can be used only for session variables.

Change your code to this, it will work

DELIMITER //
CREATE PROCEDURE one_off_update_user_info_view_type()
  BEGIN
    DECLARE batchsize BIGINT DEFAULT 1;
  END
//
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.