<分区>
关于使用 JDBC 和 MySQL 在 java 中运行查询:
replace into orders(external_id, channel_id) values ("1001","test");
我想知道订单是在数据库中插入还是替换。
<分区>
关于使用 JDBC 和 MySQL 在 java 中运行查询:
replace into orders(external_id, channel_id) values ("1001","test");
我想知道订单是在数据库中插入还是替换。
最佳答案
来自manual :
The affected-rows count makes it easy to determine whether REPLACE only added a row or whether it also replaced any rows: Check whether the count is 1 (added) or greater (replaced).
因此您可以使用 ROW_COUNT()
来获取执行查询后受影响的行数。 Replace 将更改现有行时不会更新 ROW_COUNT()
。
关于java - 检查是否插入或替换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34674260/