mysql自定义函数
2016-06-10 13:10
716 查看
//注意规避mysql关键字,可能需要重定义结束符号符delimiter $$ //声明函数:参数类型以及返回类型 create function insertY(start int(11),end int(11)) returns varchar(255) //开始函数实现 begin //定义一个变量 declare i int(11); //给变量赋值,需要加set set i = start; //while condition do,end while while i <= end do //if condition then,else,end if //注意比较是否相等使用 = 而不是 == if (i mod 2 = 0) then insert into A values(i); else insert into B values(i); end if; insert into C values(i); set i = i + 1; end while; return "finished"; end
//创建一个查询过程
create procedure sq(qq_ varchar(15)) begin select * from T_qq_9 where qq = qq_ union select * from T_qq_10 where qq = qq_ union select * from T_qq_5 where qq = qq_ union select * from T_qq_6 where qq = qq_ union select * from T_qq_7 where qq = qq_ union select * from T_qq_8 where qq = qq_; end call sq("343234223");
相关文章推荐
- MySQL中的integer 数据类型
- MySQL存储过程
- mysql中int、bigint、smallint 和 tinyint的区别与长度
- mysql load data 导出、导入 csv
- source命令执行SQL脚本文件
- MySQL创建用户及权限控制
- MySQL管理数据表
- linux下mysql添加用户
- mysql procedure
- mysql触发器
- MySQL 备份和恢复策略
- mac下安装mysql(转载)
- mysql 修改编码 Linux/Mac/Unix/通用(杜绝修改后无法启动的情况!)
- MySQL数据的导出、导入(mysql内部命令:mysqldump、mysql)
- mysql数据行转列
- Linux下修改MySQL编码的方法
- MySQL Server 日志
- MySQL 安全事宜
- MySQL 备份与恢复