Mega Code Archive

 
Categories / MySQL Tutorial / Procedure Function
 

Variable scope

mysql> mysql> delimiter $$ mysql> mysql> CREATE PROCEDURE myProc()     -> BEGIN     ->         DECLARE outer_variable VARCHAR(20);     ->         BEGIN     ->                 DECLARE inner_variable VARCHAR(20);     ->                 SET inner_variable='This is my private data';     ->         END;     ->         SELECT inner_variable,' This statement causes an error ';     ->     -> END$$ Query OK, 0 rows affected (0.00 sec) mysql> mysql> delimiter ; mysql> call myProc(); ERROR 1054 (42S22): Unknown column 'inner_variable' in 'field list' mysql> drop procedure myProc; Query OK, 0 rows affected (0.00 sec) mysql>