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

六眼飞鱼酱① 提交于 2021-02-14 08:21:54

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!