本文主要是介绍Result consisted of more than one row,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
呀,开始学习写存储结构了。呼呲呼呲的写了一个删除数据,返回修改的数据数量和剩余的数据数量的存储结构
mysql>CREATE PROCEDURE removeGoodAndReturnInfos(IN b_name VARCHAR(40),OUT delete_goods SMALLINT UNSIGNED,OUT goodCounts SMALLINT UNSIGNED)
mysql>BEGIN
mysql>DELETE from tdb_goods where brand_name = b_name;
mysql>SELECT ROW_COUNT() from tdb_goods INTO delete_goods;
mysql>SELECT COUNT(good_id) from tdb_goods INTO goodCounts;
mysql>END
完工!来执行一下!
mysql>call removeGoodAndReturnInfos("索尼",@a,@b);
ERROR 1172 (42000): Result consisted of more than one row
欸,怎么出错了。
一看到这个错误,就知道是在使用SELECT INTO的时候出现了多于一行的情况,导致removeGoodAndReturnInfos这个存储过程执行错误
由于我在记录改变行数多写了from tdb_goods,将这块去掉,修改如下:
mysql>delimiter //
mysql>CREATE PROCEDURE removeGoodAndReturnInfos(IN b_name VARCHAR(40),OUT mysql>delete_goods SMALLINT UNSIGNED,OUT goodCounts SMALLINT UNSIGNED)
mysql>BEGIN
mysql>DELETE from tdb_goods where brand_name = b_name;
mysql>SELECT ROW_COUNT() INTO delete_goods;
mysql>SELECT COUNT(goods_id) from tdb_goods INTO goodCounts;
mysql>END
mysql>//
我去~,咋又出下你问题!
mysql>call procedure removeGoodAndReturnInfos("宏基",@a,@b);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'procedure removeGoodAndReturnInfos("宏基",@a,@b)' at line 1
额,多写了procedure,把这个去掉,再试试。
mysql> call removeGoodAndReturnInfos("IBM",@a,@b);
Query OK, 0 rows affected (0.00 sec)
哈哈哈,成功了!看看变量值。
mysql> select @a,@b;
+------+------+
| @a | @b |
+------+------+
| 2 | 9 |
+------+------+
1 row in set (0.00 sec)
这个问题提醒我们,编写的时候一定要注意注意再注意。多留点神。
附上学习存储过程的思维导图
这篇关于Result consisted of more than one row的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!