• mysql存贮过程编写


    这篇并不是说如何去写存贮过程,只是自己以前在测试过程中主要是查看,获取数据库里的数据,偶尔删除一些脏数据。然后这次因为手动测试组想做一个批量审批的测试,因为流程繁杂,因此想用一种快速的方式去做,于是就想到了存贮过程直接操作db。这也是第一次写这玩意,边查边写,最后也踉踉跄跄的写出来了,其实就和咱们平时用开发语言写脚本差不多,知识基础的语法不通罢了。下面直接贴上代码,留在这里也算是一个节点。

    BEGIN

    #定义各种变量,其中tid_是从输入参数 declare title_ VARCHAR(255); declare cuid VARCHAR(255); declare uid VARCHAR(64); declare uid_ VARCHAR(64); declare loc INT DEFAULT 2; declare size INT DEFAULT 1; declare confim VARCHAR(255); declare confim_ VARCHAR(255); declare cunt INT;
    #这里有一个关键字into,就是把查询到的结果保存到title_变量,下面还有一个select title_语句,这表示执行时把变量显示出来,有点类似print的意思   
    select title into title_ from dyoa_task where id = tid_; select confirm into confim from dyoa_task where id = tid_; update dyoa_task SET status = 1, doing = '', do_after = '', do_berfor = confim WHERE id = tid_;
    #concat拼接函数 #
    select CONCAT('|',confim) into confim; #这是获取字符串中“|”符号的个数 select LENGTH(confim)-LENGTH( REPLACE(confim,'|','') ) into size; #select size; select count(*) into cunt from dyoa_confirm_list where tid = tid_; if cunt > 0 THEN delete from dyoa_confirm_list where tid = tid_; #select tid_; end if; while size>0 do
    #substring,截取字符串
    select SUBSTRING_INDEX(confim, '|', 1) into cuid; #select cuid; #select REPLACE(confim,cuid,'') into confim_; select SUBSTRING_INDEX(confim, '|', -size) into confim_; select confim_; set confim = confim_; SELECT SUBSTRING(cuid,4) into uid; #select uid; select REPLACE(uid,'_','') into uid_; select uid_; set size = size - 1; #select size; #select POSITION('|' IN confim, '|', size) into loc; #select loc; #while size>0 do insert into dyoa_confirm_list(uid,tid,status,mark,ctime,utime) values(uid_,tid_,1,'shenpi',UNIX_TIMESTAMP(),UNIX_TIMESTAMP()); #set loc = loc + 1; end while; end if; END

    整个代码功能其实不负责,主要是一些字符串的处理占了一些代码。

  • 相关阅读:
    窗口宽高 滚动条滚动距离 元素的文档坐标和窗口坐标
    parentNode parentElement childNodes children
    ffmpeg 提取mp3
    Linux修改时区的正确方法
    pip
    wireguard
    Nextcloud挂载谷歌云盘搭建
    ts合并
    screen
    google drive
  • 原文地址:https://www.cnblogs.com/jingwei/p/5683740.html
Copyright © 2020-2023  润新知