loop循环不需要初始条件,这点和while 循环相,同时和repeat循环一样不需要结束条件, leave语句的意义是离开循环。mysql怎么调用存储过程
1. mysql > DELIMITER
2. mysql > CREATE PROCEDURE proc6 ()
3. -> begin
4. -> declare v int;
5. -> set v=0;
6. -> LOOP_LABLE:loop
7. -> insert into t values(v);
8. -> set v=v1;
9. -> if v >=5 then
10. -> leave LOOP_LABLE;
11. -> end if;
12. -> end loop;
13. -> end;
14. ->
15.mysql > DELIMITER ;
LABLES 标号:
标号可以用在begin repeat while 或者loop 语句前,语句标号只能在合法的语句前面使用。可以跳出循环,使运行指令达到复合语句的最后一步。
ITERATE迭代ITERATE:
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=v1;
10. -> ITERATE LOOP_LABLE;
11. -> end if;
12. -> insert into t values(v);
13. -> set v=v1;
14. -> if v>=5 then
15. -> leave LOOP_LABLE;
16. -> end if;
17. -> end loop;
18. -> end;
19. ->
20.mysql > DELIMITER ;
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
MySQL存储过程的基本函数字符串类
CHARSET(str)
CONCAT (string2 [,... ])
INSTR (string ,substring )
LCASE (string2 )
LEFT (string2 ,length )
LENGTH (string )
LOAD_FILE (file_name )
LOCATE (substring , string [,start_position ] ) 同INSTR,但可指定开始位置
LPAD (string2 ,length ,pad )
LTRIM (string2 )
REPEAT (string2 ,count )
REPLACE (str ,search_str ,replace_str )
RPAD (string2 ,length ,pad)
RTRIM (string2 )
STRCMP (string1 ,string2 )
SUBSTRING (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);
10.
11.| substring('abcd',1,2) |
12.
13.| ab |
14.
15.1 row in set (0.02 sec)
TRIM([[BOTH|LEADING|TRAILING][padding] FROM]string2)
UCASE (string2 )
RIGHT(string2,length)
SPACE(count)
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
数学类
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/tongxinshuyu/article-59713-7.html
美国终于跳出来警告伊拉克政府