试图找出为什么它是空的。我原以为会打印出7张。
mysql> set @total = 0;
Query OK, 0 rows affected (0.00 sec)
mysql> call getAuthorCount(@total);
+------------------------+
| count(distinct author) |
+------------------------+
| 7 |
+------------------------+
1 row in set (0.00 sec)
Query OK, 0 rows affected (0.02 sec)
mysql> select @total as totalauthors;
+--------------+
| totalauthors |
+--------------+
| NULL |
+--------------+这个过程,
mysql> create procedure getAuthorCount(out authorcount int)
-> begin
-> select count(distinct author) from libbooks;
-> end
-> //发布于 2012-09-14 19:18:57
你应该使用INOUT参数-
CREATE PROCEDURE getAuthorCount(INOUT authorcount INT)
BEGIN
SELECT count(DISTINCT author) FROM libbooks;
END示例:
当@total值为原样(0进0出)时为:
DROP PROCEDURE getAuthorCount;
DELIMITER $$
CREATE PROCEDURE getAuthorCount(INOUT authorcount INT)
BEGIN
-- SET authorcount = 100;
END$$
DELIMITER ;
SET @total = 0;
CALL getAuthorCount(@total);
SELECT @total AS totalauthors;
+--------------+
| totalauthors |
+--------------+
| 0 |
+--------------+当@total value替换为存储过程中的新值时为:
DROP PROCEDURE getAuthorCount;
DELIMITER $$
CREATE PROCEDURE getAuthorCount(OUT authorcount INT)
BEGIN
SET authorcount = 100;
END$$
DELIMITER ;
SET @total = 0;
CALL getAuthorCount(@total);
SELECT @total AS totalauthors;
+--------------+
| totalauthors |
+--------------+
| 100 |
+--------------+https://stackoverflow.com/questions/12422667
复制相似问题