gpt4 book ai didi

mysql - 有什么方法可以区分 MYSQL 更新的 0 行受影响的情况?

转载 作者:行者123 更新时间:2023-11-29 03:04:50 25 4
gpt4 key购买 nike

假设我有一个名为“t”的表

---------------
| key | value |
---------------
| 1 | abc |
| 2 | def |
---------------

考虑两个 MYSQL 查询

  1. UPDATE t SET value='abc' WHERE key=1
  2. UPDATE t SET value='abc' WHERE key=3

执行这两个查询还会使“受影响的行”为 0(即不更新任何行),因为第一个查询是非更新更新,第二个查询是非匹配更新。

有什么办法可以区分这两种情况吗?

最佳答案

如果您只想要“匹配”行的数量(而不是“已更改”行的数量),您可以按照此处所述设置 CLIENT_FOUND_ROWS:

http://dev.mysql.com/doc/refman/5.5/en/mysql-affected-rows.html

For UPDATE statements, the affected-rows value by default is the number of rows actually changed. If you specify the CLIENT_FOUND_ROWS flag to mysql_real_connect() when connecting to mysqld, the affected-rows value is the number of rows “found”; that is, matched by the WHERE clause.

关于mysql - 有什么方法可以区分 MYSQL 更新的 0 行受影响的情况?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17398301/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com