mysql - mysql 使用 IF NOT NULL 作为事务的一部分
问题描述
我正在使用 MySQL 事务。如果初始 where
myHistoryNum
结果(匹配名称+rowActive)不为NULL,则继续事务。
我尝试了各种组合,但是无法让insert
语句在设置时触发myHistoryNum
。
history | uuid | name | rowActive
24 | abcd | Art | 1 <<< is match, trigger an insert
999 | zxcv | Art | 0 <<< no match, do not trigger insert
start transaction;
select @myHistNum := max(history), @olduuid := uuid
from mytable WHERE (name=art AND rowActive=1);
# START IS NOT NULL test
CASE WHEN @myHistNum IS NOT NULL THEN
set @histNum = @histNum + 1;
INSERT INTO mytable
.....
END; <<<ALT, tried END AS;
commit;
也试过
IF @myHistNum IS NOT NULL
THEN
.....
END IF;
commit;
解决方案
如果我没记错的话,控制流语句(如 IF、WHEN)只能在 MySQL 的存储程序中使用
推荐阅读
- javascript - VoiceStates 不更新 discord.js
- node.js - 无法从 mongodb 获取文件元数据,因为 Gridfs-stream 的 gfs 未定义
- flutter - 抽屉中心对齐问题
- reactjs - 响应中的 Cookie 未保存在浏览器中 - Spring Boot 和 React
- ffmpeg - 如何让 FFmpeg 将 PNG 序列转换为 WEBP 序列,而不是制作单个动画 WEBP
- r - 用于 setwd 到谷歌驱动器的 R 函数
- android - 如何从 Android Debug Bridge (ADB) 获取点击流日志
- linq-to-sql - 从左连接中选择左实体,其中一列基于右实体
- quarkus - 观察 @Initialized(ApplicationScoped.class) 时,持久性提供程序在静态初始化阶段不可用
- javascript - 即使参数值与博客文章的标题匹配,页面也无法正确呈现