Mysql

如何檢查是否在 MySQL 中執行了更新查詢?

  • January 14, 2022

我在 MySQL 中有一個更新查詢,我想根據我的更新查詢是否執行返回 true 或 false。有什麼方法可以查到更新查詢是否被執行?

UPDATE table SET table.name = "Anthony" WHERE table.id = 3;
IF (queryUpdated) THEN
   SELECT 1 AS updated;
ELSE
   SELECT 0 AS updated;
END IF;

我懷疑你想要這個ROW_COUNT()功能

UPDATE table SET table.name = "Anthony" WHERE table.id = 3;
SELECT CASE WHEN ROW_COUNT() > 0 THEN 1 ELSE 0 END AS updated;

引用自:https://dba.stackexchange.com/questions/306090