Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the @ symbol means on a Procedure in MySQL?

What's the difference between accessing a variable with @ or without?

like image 499
DontVoteMeDown Avatar asked Sep 01 '25 16:09

DontVoteMeDown


2 Answers

The @ makes it a user defined session variable. Otherwise it would be locally scoped variable (in a stored procedure), you would have to DEFINE your local before you can SET it. You could also set a global system variable (with SET GLOBAL or SET @@global) if you wanted to. As well as a session system variable with SET SESSION var or SET @@session var or SET @@var.

More details about SET from the documentation: If no modifier is present, SET changes the session variable (that's why you DEFINE your locals in the stored procedure first). If you set several system variables, the most recent GLOBAL or SESSION modifier in the statement is used for following variables that have no modifier specified.

More (and some good examples) here:

  • MySQL: @variable vs. variable. Whats the difference?
  • Variables in Stored Programs
like image 194
Pavel Veller Avatar answered Sep 04 '25 11:09

Pavel Veller


That notation is used for user-defined variables, as explained here: http://dev.mysql.com/doc/refman/5.0/en/user-variables.html

like image 38
Ja͢ck Avatar answered Sep 04 '25 12:09

Ja͢ck