mysql存储过程能返回update更新操作的结果吗
不用存储过程的时候,mysql的update操作成功会返回1,把update放进存储过程中后,怎样获取是否更新成功呢?...
不用存储过程的时候,mysql的update操作成功会返回1,把update放进存储过程中后,怎样获取是否更新成功呢?
展开
1个回答
展开全部
在存储过程中使用ROW_COUNT()
mysql> select * from a1;
-> //
+------+-------+
| id | name |
+------+-------+
| 1 | timac |
+------+-------+
1 row in set (0.00 sec)
mysql> \d ;
mysql> update a1 set name='king' where id=1;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select row_count();
+-------------+
| row_count() |
+-------------+
| 1 |
+-------------+
1 row in set (0.00 sec)
mysql> insert into a1 values(2,'K1'),(3,'K2');
Query OK, 2 rows affected (0.00 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> select row_count();
+-------------+
| row_count() |
+-------------+
| 2 |
+-------------+
1 row in set (0.00 sec)
mysql> update a1 set name='kings' where id=4;
Query OK, 0 rows affected (0.00 sec)
Rows matched: 0 Changed: 0 Warnings: 0
mysql> select row_count();
+-------------+
| row_count() |
+-------------+
| 0 |
+-------------+
1 row in set (0.00 sec)
只有返回的row_count()值大小还判断是否成功
mysql> select * from a1;
-> //
+------+-------+
| id | name |
+------+-------+
| 1 | timac |
+------+-------+
1 row in set (0.00 sec)
mysql> \d ;
mysql> update a1 set name='king' where id=1;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select row_count();
+-------------+
| row_count() |
+-------------+
| 1 |
+-------------+
1 row in set (0.00 sec)
mysql> insert into a1 values(2,'K1'),(3,'K2');
Query OK, 2 rows affected (0.00 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> select row_count();
+-------------+
| row_count() |
+-------------+
| 2 |
+-------------+
1 row in set (0.00 sec)
mysql> update a1 set name='kings' where id=4;
Query OK, 0 rows affected (0.00 sec)
Rows matched: 0 Changed: 0 Warnings: 0
mysql> select row_count();
+-------------+
| row_count() |
+-------------+
| 0 |
+-------------+
1 row in set (0.00 sec)
只有返回的row_count()值大小还判断是否成功
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
今至电子科技有限公司
2024-08-23 广告
2024-08-23 广告
数据库备份是确保数据安全与业务连续性的关键环节。我们上海今至电子科技有限公司高度重视数据保护,定期执行全面的数据库备份策略。这包括使用先进工具和技术,对关键业务数据进行自动化备份,并存储在安全可靠的外部存储介质或云端。通过定期验证备份的完整...
点击进入详情页
本回答由今至电子科技有限公司提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询