Mega Code Archive

 
Categories / MySQL / Procedure Function
 

Inner variable shadows the outter variable

mysql> mysql> delimiter $$ mysql> mysql> CREATE PROCEDURE myProc()     -> BEGIN     ->         DECLARE my_variable VARCHAR(20);     ->         SET my_variable='This value was set in the outer block';     ->         BEGIN     ->                 DECLARE my_variable VARCHAR(20);     ->                 SET my_variable='This value was set in the inner block';     ->         END;     ->         SELECT my_variable, 'Can''t see changes made in the inner block';     -> END$$ Query OK, 0 rows affected (0.00 sec) mysql> mysql> delimiter ; mysql> call myProc(); +----------------------+-------------------------------------------+ | my_variable          | Can't see changes made in the inner block | +----------------------+-------------------------------------------+ | This value was set i | Can't see changes made in the inner block | +----------------------+-------------------------------------------+ 1 row in set (0.00 sec) Query OK, 0 rows affected, 2 warnings (0.00 sec) mysql> drop procedure myProc; Query OK, 0 rows affected (0.00 sec) mysql> mysql>