mysql触发器使用if..then sql elseif then end if; 转自 吴大哥

阅读: 评论:0

mysql触发器使用if..then   sql      elseif then      end if;   转自 吴大哥

mysql触发器使用if..then sql elseif then end if; 转自 吴大哥

 

 

mysql 触发器 if then elseif else 的运用

自己第一次写触发,想使用两个三个条件语句并列使用,但是不管怎么写都保存不了,最后看了吴大哥的博文,试了是if..then ...end if;中使用if并列是可以。

我是不知道是为什么,有大神知道可以详解。下面贴上我的触发器:

  

DROP TRIGGER `down`;CREATE DEFINER=`root`@`localhost` TRIGGER `down` BEFORE UPDATE ON `ne`
FOR EACH ROW if  '1'='1' then #Step 1#拆除报警:if new.down_status = '1'  theninsert into ne_alarm_his(ID, alarm_id, company_id,  ne_no    , hierarchy    , ne_model_id, alarm_type_id  , alarm_level, alarm_up_time    , alarm_last_time, occur_count, ack_user, ack_time, ack_res, ack_remark, alarmtime, areaid, alermaddress              , gps_lon        , gps_lat          , car_id,AuditStatus ,status) values(uuid(), getSerialNumber('报警编号'),newpany_id, _no ,new.hierarchy, _model_id  , 1,        null,        new.down_starttime ,    now()       ,  null        , null        , null      , null       , null         , now()       , null  , aphical_address2  , new.gps_lon2 ,new.gps_lat2, new.car_id, '0',null );end if;#Step 2:#低电量报警if new.low_power_status = '1' theninsert into ne_alarm_his(ID, alarm_id, company_id,  ne_no    , hierarchy    , ne_model_id, alarm_type_id  , alarm_level, alarm_up_time             , alarm_last_time, occur_count, ack_user, ack_time, ack_res, ack_remark, alarmtime, areaid, alermaddress              , gps_lon        , gps_lat   , car_id,AuditStatus , status) values(uuid(), getSerialNumber('报警编号'), newpany_id, _no, new.hierarchy, _model_id  , 5,        null,        new.low_power_starttime ,    now()       ,  null        , null        , null      , null       , null         , now()       , null  , aphical_address2  , new.gps_lon2 ,new.gps_lat2, new.car_id, '0',    null );end if;#Step 3:#断电报警if new.pwr_down_status = '1' theninsert into ne_alarm_his(ID, alarm_id, company_id,  ne_no    , hierarchy    , ne_model_id, alarm_type_id  , alarm_level, alarm_up_time            , alarm_last_time, occur_count, ack_user, ack_time, ack_res, ack_remark, alarmtime, areaid, alermaddress              , gps_lon        , gps_lat   , car_id, AuditStatus ,status) values(uuid(), getSerialNumber('报警编号'), newpany_id, _no, new.hierarchy, _model_id  , 6,        null,        new.pwr_down_starttime ,    now()       ,  null        , null   , null    , null  , null      , now()    , null  , aphical_address2  , new.gps_lon2 ,new.gps_lat2, new.car_id,  '0',   null );end if;end if;

 

 判断是否包含字符串,

  使用函数   locate('admin','ad')    

  如果包含,返回>0的数,否则返回0

  set @alarmType = new.alerttypeset;if (locate(@alarmType , '9'))>0  and new.run_status !=old.run_status and new.run_status = '1' then..
end if;

 mysql中字符串的拼接不能使用加号+,用concat函数:

 set @vcommandPara =concat('&Uconfig=','replynumber');

 

 

 下面是吴大哥的博文:

create procedure dbname.proc_getGrade  
(stu_no varchar(20),cour_no varchar(10)) BEGIN declare stu_grade float; select

本文发布于:2024-01-31 12:45:36,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/170667633728616.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:触发器   转自   大哥   mysql   elseif
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23