匿名用户
1级
2016-06-20 回答
你这种格式的没有,不过这个变量还是可以用下面这种方法实现的。
mysql> delimiter //
mysql>
mysql> CREATE PROCEDURE curdemo(IN V_GROUP INT)
-> BEGIN
-> DECLARE done INT DEFAULT 0;
-> DECLARE a INT;
-> DECLARE b CHAR(16);
->
-> DECLARE cur1 CURSOR FOR SELECT id,name FROM student where classid=V_GROUP;
-> DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
->
-> OPEN cur1;
->
-> REPEAT
-> FETCH cur1 INTO a, b;
-> select a,b;
-> UNTIL done END REPEAT;
->
-> CLOSE cur1;
-> END
->
->
-> //
Query OK, 0 rows affected (0.20 sec)
mysql>
mysql> delimiter ;
mysql>
mysql> SELECT id,name,classid FROM student ;
+----------+--------+---------+
| id | name | classid |
+----------+--------+---------+
| 91010101 | 丁乙甲 | 10101 |
| 91010102 | 索春龙 | 10101 |
| 91010103 | 刘莉莉 | 10101 |
| 91010104 | 隋鑫 | 10101 |
| 91010105 | 长命 | 10101 |
| 91010201 | 河江山 | 10102 |
| 91010202 | 祝立业 | 10102 |
| 91010203 | 姚桂娇 | 10102 |
| 91010204 | 张冬梅 | 10102 |
| 91020101 | 蒋旭 | 10201 |
| 91020102 | 邱介臣 | 10201 |
| 91020103 | 王晓燕 | 10201 |
| 91020104 | 夏丽佳 | 10201 |
| 91020201 | 熊建业 | 10202 |
| 91020202 | 丛俊江 | 10202 |
| 91020203 | 周静燕 | 10202 |
| 91020204 | 黄爽 | 10202 |
| 91020301 | 魏国兴 | 10203 |
| 91020302 | 蒋洪涛 | 10203 |
| 91020303 | 倪春红 | 10203 |
| 91030101 | 张文天 | 10301 |
| 91030102 | 姜洋 | 10301 |
| 91030103 | 赵聪 | 10301 |
| 91030201 | 王飞 | 10302 |
+----------+--------+---------+
24 rows in set (0.00 sec)
mysql>
mysql> CALL curdemo(10101);
+----------+--------+
| a | b |
+----------+--------+
| 91010101 | 丁乙甲 |
+----------+--------+
1 row in set (0.00 sec)
+----------+--------+
| a | b |
+----------+--------+
| 91010102 | 索春龙 |
+----------+--------+
1 row in set (0.00 sec)
+----------+--------+
| a | b |
+----------+--------+
| 91010103 | 刘莉莉 |
+----------+--------+
1 row in set (0.00 sec)
+----------+------+
| a | b |
+----------+------+
| 91010104 | 隋鑫 |
+----------+------+
1 row in set (0.00 sec)
+----------+------+
| a | b |
+----------+------+
| 91010105 | 长命 |
+----------+------+
1 row in set (0.00 sec)
+----------+------+
| a | b |
+----------+------+
| 91010105 | 长命 |
+----------+------+
1 row in set (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
mysql>