问题
What's the difference between accessing a variable with @
or without?
回答1:
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
回答2:
That notation is used for user-defined variables, as explained here: http://dev.mysql.com/doc/refman/5.0/en/user-variables.html
来源:https://stackoverflow.com/questions/10518026/what-does-the-symbol-means-on-a-procedure-in-mysql