Demonstrates the levels of definition of local variables. : Variable Assignment « Procedure Function « SQL / MySQL






Demonstrates the levels of definition of local variables.

     
mysql>
mysql>
mysql>
mysql>
mysql> delimiter $$
mysql>
mysql>
mysql> CREATE PROCEDURE test()
    -> BEGIN
    ->    DECLARE x INT DEFAULT 0;
    ->    BEGIN
    ->       DECLARE x INT DEFAULT 1;
    ->       IF TRUE THEN
    ->       BEGIN
    ->          DECLARE x INT DEFAULT 2;
    ->          SELECT x;
    ->       END;
    ->       END IF;
    ->    SELECT x;
    ->    END;
    -> SELECT x;
    -> END$$
Query OK, 0 rows affected (0.00 sec)

mysql>
mysql> delimiter ;
mysql>
mysql> drop procedure test;
Query OK, 0 rows affected (0.00 sec)

mysql>
mysql>

   
    
    
    
    
  








Related examples in the same category

1.Use select into to assign value to an Integer variable
2.Variable Assignment