- 内部的变量在其作用域范围内享有更高的优先权,当执行到end时,由于处于作用域之外,所以变量消失
- 通过下面的代码进行说明
mysql> DELIMITER // mysql> create procedure proc3() -> begin -> declare x1 varchar(5) default 'outer'; -> begin -> declare x1 varchar(5) default 'inner'; -> select x1; -> end; -> select x1; -> end; -> // mysql> DELIMITER ;
mysql> call proc3(); +-------+ | x1 | +-------+ | inner | +-------+ 1 row in set +-------+ | x1 | +-------+ | outer | +-------+ 1 row in set
第一次输出的x1值为inner,第二次输出的值为outer,因为此时执行到了end, ‘inner’变量消失