MySQL Has the concept of user-defined variables.
They is loosely typed variables that may is initialized somewhere in a session and keep their value until the session end S. They @ is prepended with a sign, like this:@var Can initialize this variable with a SET statement or inside in a query: SET @var = 1SELECT @var2 := 2
When you develop a stored procedure MySQL in, you can pass the input parameters and declare the local variables: delimiter //create procedure Prc_test ( var int begin declare< Span class= "PLN" > var2 int;set var2 = 1 select Var2;end; //delimiter ;
These variables is not prepended with any prefixes. The difference between a procedure variable and a session-specific user-defined variable is this procedure variable is REI Nitialized to each time NULL the procedure are called, while the session-specific variable are not: CREATE PROCEDUREPrc_test()BEGIN DECLAREVar2 INTDEFAULT 1; SETVar2:=Var2+ 1; SET @Var2:= @Var2+ 1; SELECTVar2, @Var2;END;SET @var2 = 1; Call Prc_test@var2------2< Span class= "PLN" > 2call prc_test (); @var2------2< Span class= "PLN" > 3call prc_test (); @var2------2< Span class= "PLN" > 4
As can see, var2 (procedure variable) are reinitialized each time the procedure are called, while @var2 (SESSION-SPECIF IC variable) is not. (in addition to user-defined variables, MySQL also have some predefined "system variables", which may "Global V Ariables "such as @@global.port or" session variables "such as @@session.sql_mode ; these" session variables "is unrelated to session-specific user-defined variables.) |