这篇并不是说如何去写存贮过程,只是自己以前在测试过程中主要是查看,获取数据库里的数据,偶尔删除一些脏数据。然后这次因为手动测试组想做一个批量审批的测试,因为流程繁杂,因此想用一种快速的方式去做,于是就想到了存贮过程直接操作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

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

mysql存贮过程编写的更多相关文章

  1. Mysql加锁过程详解(6)-数据库隔离级别(1)

    Mysql加锁过程详解(1)-基本知识 Mysql加锁过程详解(2)-关于mysql 幻读理解 Mysql加锁过程详解(3)-关于mysql 幻读理解 Mysql加锁过程详解(4)-select fo ...

  2. MySQL 储存过程-原理、语法、函数详细说明

    Mysql储存过程是一组为了完成特定功能的SQL语句集,经过编译之后存储在数据库中,当需要使用该组SQL语句时用户只需要通过指定储存过程的名字并给定参数就可以调用执行它了,简而言之就是一组已经写好的命 ...

  3. MySQL安装过程net start mysql 启动失败 报“错误2,系统找不到文件”的解决办法

    MySQL安装过程net start mysql 启动失败 报“错误2,系统找不到文件”的解决办法 错误2,系统找不到文件. 开始...运行... regedit  注册表项: HKEY_LOCAL_ ...

  4. mysql安装过程中出现错误ERROR 1820 (HY000): You must SET PASSWORD before executing this statement解决

    mysql安装过程中出现错误ERROR 1820 (HY000): You must SET PASSWORD before executing this statement解决   最近新装好的my ...

  5. MySQL关闭过程详解和安全关闭MySQL的方法

    MySQL关闭过程详解和安全关闭MySQL的方法 www.hongkevip.com 时间: -- : 阅读: 整理: 红客VIP 分享到: 红客VIP(http://www.hongkevip.co ...

  6. 24、jQuery常用AJAX-API/Java调用MySQL / Oracle过程与函数

      1)掌握jQuery常用AJAX-API 2)掌握Java调用MySQL / Oracle过程与函数 一)jQuery常用AJAX-API 目的:简化客户端与服务端进行局部刷新的异步通讯 (1)取 ...

  7. mysql 安装过程中的错误:my-template.ini could not be processed and written to XXX\my.ini.Error code-1

    安装mysql的过程中,在最后配置mysql时,提示错误:Configuration file tmeplate E:\编程\MySQL\my-template.ini could not be pr ...

  8. Mysql加锁过程详解(8)-理解innodb的锁(record,gap,Next-Key lock)

    Mysql加锁过程详解(1)-基本知识 Mysql加锁过程详解(2)-关于mysql 幻读理解 Mysql加锁过程详解(3)-关于mysql 幻读理解 Mysql加锁过程详解(4)-select fo ...

  9. Mysql加锁过程详解(9)-innodb下的记录锁,间隙锁,next-key锁

    Mysql加锁过程详解(1)-基本知识 Mysql加锁过程详解(2)-关于mysql 幻读理解 Mysql加锁过程详解(3)-关于mysql 幻读理解 Mysql加锁过程详解(4)-select fo ...

随机推荐

  1. Struts2笔记——struts.xml配置详解

    访问HelloWorld应用的路径的设置 * 在struts1中,通过<action path=“/primer/helloWorldAction.action”>节点的path属性指定访 ...

  2. Android:开发环境

    一.JAVA SDK(JDK)的安装 http://www.cnblogs.com/tinyphp/p/3664598.html 二.ADT-Bundle 包含了Eclipse.ADT插件和SDK T ...

  3. lua 的 WriteFile 和 ReadFile

    lua 的 ReadFile 和 WriteFile 注意: lua 代码中的 string 可以包含二进制数据 string.len(str) 不会被 '\0' 截断 从 lua 传入 c 时: 需 ...

  4. 2、Spring的LocalSessionFactoryBean创建过程源码分析

    spring的LocalSessionFactoryBean生成过程与hibernate的SessionFactory生成过程是高度吻合的. 为了后面源码分析,首先讲解一个接口,一个类的功能:①.接口 ...

  5. CEdit的简单用法

    今晚闲来无事,写篇博文聊解解闷~ CEdit这个空间类,我之前倒是用过,不过那个时候用的还比较菜,现在么,依旧比较菜~ 首先,因为我今天刚做完了一个局域网聊天软件,用的就是CEdit来显示和获取数据的 ...

  6. jxl导入/导出excel

    1.jxl导入/导出excel案例,黏贴即可运行 package junit.test; import java.io.File; import java.io.IOException; import ...

  7. ubuntu 安装 rabbitmq-server

    Rabbitmq 是用 erlang 语言写的,所以我们需要安装 Erlang,安装 erlang 又需要安装 python 与 simplejson,所以我们从python开始: 1.安装 pyth ...

  8. AI中去掉页面边框

    其实也没啥说的,就是很多人在百度中问这个在AI中这样除去页面边框,其实很简单,用快捷组合键  ctrl+shift+H  就行啦,边框自己就没了

  9. depth_write

    Sets whether or not this pass renders with depth-buffer writing on or not. Format: depth_write <o ...

  10. 函数fsp_fill_free_list

    /**********************************************************************//** Puts new extents to the ...