1

I wanted to know what is the difference between @variablename and variablename. All the help would be appreciated.

doniyor
  • 36,596
  • 57
  • 175
  • 260
user3848891
  • 101
  • 5
  • 2
    possible duplicate of [MySQL: @variable vs. variable. Whats the difference?](http://stackoverflow.com/questions/1009954/mysql-variable-vs-variable-whats-the-difference) – Johan Hjalmarsson Aug 01 '14 at 13:01

1 Answers1

1
variablename

Local variables

Local variables are declared within stored procedures and are only valid within the BEGIN…END block where they are declared. Local variables can have any SQL data type.

@variablename

User variables

In MySQL stored procedures, user variables are referenced with an ampersand (@) prefixed to the user variable name (for example, @x and @y). You can store a value in a user-defined variable in one statement and then refer to it later in another statement. This enables you to pass values from one statement to another. User-defined variables are session-specific. That is, a user variable defined by one client cannot be seen or used by other clients. All variables for a given client session are automatically freed when that client exits.

In MySQL the variable var1 and @var1 are two different things. @var1 is a user session variable which remains for the duration of the active session. The other is local to the stored procedure.

catalinetu
  • 630
  • 6
  • 12