我是LZ 返回的错误SQL 查询: call aa() MySQL 返回: #1312 - PROCEDURE wxl.aa can't return a result set in the given context
http://dev.mysql.com/doc/refman/5.0/en/create-procedure.html 你看看里面有说明: Before MySQL 5.0.10, stored functions created with CREATE FUNCTION must not contain references to tables, with limited exceptions. They may include some SET statements that contain table references, for example SET a:= (SELECT MAX(id) FROM t), and SELECT statements that fetch values directly into variables, for example SELECT i INTO var1 FROM t. 建议你的mysql升级。或者参照它给出的方法: mysql> delimiter //mysql> CREATE PROCEDURE simpleproc (OUT param1 INT) -> BEGIN -> SELECT COUNT(*) INTO param1 FROM t; -> END; -> // Query OK, 0 rows affected (0.00 sec)mysql> delimiter ;mysql> CALL simpleproc(@a); Query OK, 0 rows affected (0.00 sec)mysql> SELECT @a; +------+ | @a | +------+ | 3 | +------+ 1 row in set (0.00 sec)
Query OK, 0 rows affected (0.00 sec)mysql> call aa();
+----+--------+---------+
| id | typeid | content |
+----+--------+---------+
| 1 | 1 | a1 |
| 2 | 1 | a2 |
| 3 | 1 | a3 |
| 4 | 1 | a4 |
| 5 | 2 | b1 |
| 6 | 2 | b2 |
| 7 | 2 | b3 |
| 8 | 2 | b4 |
| 9 | 3 | c1 |
| 10 | 3 | c2 |
| 11 | 3 | c3 |
| 12 | 3 | c4 |
| 13 | 1 | 3 |
| 21 | 4 | 5 |
| 56 | 5 | 7 |
+----+--------+---------+
15 rows in set (0.00 sec)Query OK, 0 rows affected (0.02 sec)mysql>
返回的错误SQL 查询: call aa() MySQL 返回: #1312 - PROCEDURE wxl.aa can't return a result set in the given context
你看看里面有说明:
Before MySQL 5.0.10, stored functions created with CREATE FUNCTION must not contain references to tables, with limited exceptions. They may include some SET statements that contain table references, for example SET a:= (SELECT MAX(id) FROM t), and SELECT statements that fetch values directly into variables, for example SELECT i INTO var1 FROM t.
建议你的mysql升级。或者参照它给出的方法:
mysql> delimiter //mysql> CREATE PROCEDURE simpleproc (OUT param1 INT)
-> BEGIN
-> SELECT COUNT(*) INTO param1 FROM t;
-> END;
-> //
Query OK, 0 rows affected (0.00 sec)mysql> delimiter ;mysql> CALL simpleproc(@a);
Query OK, 0 rows affected (0.00 sec)mysql> SELECT @a;
+------+
| @a |
+------+
| 3 |
+------+
1 row in set (0.00 sec)