日期:2014-05-16 浏览次数:20736 次
在MySQL存储过程变量前加@符号代表会话变量,作用域是当前登陆的帐户,DECLARE申明的变量只在存储过程内部有效。
mysql> delimiter //
mysql> CREATE PROCEDURE pro2()
??? -> BEGIN
??? -> DECLARE d int;
??? -> SELECT MAX(id) INTO d from php_coder;
??? -> SET @dd=0;
??? -> SELECT MAX(id) INTO @dd FROM php_coder;
??? -> END;
??? -> //
Query OK, 0 rows affected (0.00 sec)
mysql> call pro2();
??? -> //
Query OK, 0 rows affected (0.01 sec)
mysql> SELECT @dd;
??? -> //
+------+
| @dd |
+------+
| 7??? |
+------+
1 row in set (0.00 sec)
mysql> SELECT d//
ERROR 1054 (42S22): Unknown column 'd' in 'field list'