社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  DATABASE

mysql在不为空的情况下作为事务的一部分使用

art vanderlay • 7 年前 • 1994 次点击  

我正在使用一个mysql事务。如果首字母 where myHistoryNum 结果(match name+rowactive)不为空,然后继续事务。

我试过各种组合,但是没有得到 insert 要在何时触发的语句 肌史 被设置。

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;
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/40292
文章 [ 1 ]  |  最新文章 7 年前