MySQL存储过程详解(8)

来源:未知 责任编辑:责任编辑 发表时间:2013-12-06 08:46 点击:

1.    通过引用复合语句的标号,来从新开始复合语句

2.  mysql > DELIMITER // 

3.  mysql > CREATE PROCEDURE proc10 () 

4.       -> begin

5.       -> declare v int; 

6.       -> set v=0; 

7.       -> LOOP_LABLE:loop 

8.      -> if v=3 then  

9.      -> set v=v+1; 

10.        -> ITERATE LOOP_LABLE; 

11.        -> end if; 

12.     -> insert into t values(v); 

13.     -> set v=v+1; 

14.        -> if v>=5 then

15.        -> leave LOOP_LABLE; 

16.     -> end if; 

17.     -> end loop; 

18.     -> end; 

19.     -> // 

20.mysql > DELIMITER ;

 

 

9.      MySQL存储过程的基本函数

 

(1).字符串类

CHARSET(str) //返回字串字符集

CONCAT (string2 [,... ]) //连接字串

INSTR (string ,substring ) //返回substring首次在string中出现的位置,不存在返回0

LCASE (string2 ) //转换成小写

LEFT (string2 ,length ) //从string2中的左边起取length个字符

LENGTH (string ) //string长度

LOAD_FILE (file_name ) //从文件读取内容

LOCATE (substring , string [,start_position ] ) 同INSTR,但可指定开始位置

LPAD (string2 ,length ,pad ) //重复用pad加在string开头,直到字串长度为length

LTRIM (string2 ) //去除前端空格

REPEAT (string2 ,count ) //重复count次

REPLACE (str ,search_str ,replace_str ) //在str中用replace_str替换search_str

RPAD (string2 ,length ,pad) //在str后用pad补充,直到长度为length

RTRIM (string2 ) //去除后端空格

STRCMP (string1 ,string2 ) //逐字符比较两字串大小,

SUBSTRING (str , position [,length ]) //从str的position开始,取length个字符,

注:mysql中处理字符串时,默认第一个字符下标为1,即参数position必须大于等于1

1.  mysql> select substring('abcd',0,2); 

2.  +-----------------------+  

3.  | substring('abcd',0,2) | 

4.  +-----------------------+ 

5.  |                       | 

6.  +-----------------------+ 

7.  1 row in set (0.00 sec) 

8.  

9.  mysql> select substring('abcd',1,2); 

发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
用户名: 验证码:点击我更换图片
最新评论 更多>>

推荐热点

  • mysql-mmm
  • mysqldump命令——MySQL数据库备份还原
  • Oracle数据导入MySQL的快捷工具:MySQL Migration Toolkit
  • 简简单单储存过程——循环一个select结果集
  • MySQL数据库十大优化技巧
  • Mysql主主复制架构配置
  • Mysql安装笔记
  • Mysql的Procedure 参数为NULL问题分析
  • MySQL Stmt预处理提高效率问题的小研究
网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
Copyright © 2008-2015 计算机技术学习交流网. 版权所有

豫ICP备11007008号-1