mysql循环方法总结
来源:互联网 发布:java并发编程应用在哪 编辑:程序博客网 时间:2024/05/18 21:08
MySQL与Oracle 差异条件循环语句
ii_weekly_day := 'MON';
ELSIF iv_weekly_day = 'TUE' THEN
ii_weekly_day := 'TUE';
END IF;IF iv_weekly_day = 'MON'THEN
set ii_weekly_day = 'MON';
ELSEIF iv_weekly_day = 'TUE' THEN
set ii_weekly_day = 'TUE';
END IF; 1. mysql和oracle除了关键字有一个字差别外(ELSEIF/ELSIF),if语句使用起来完全相同.
2. mysql if语句语法: 摘自 MySQL 5.1 参考手册 20.2.12.1. IF语句
IF search_condition THEN statement_list
[ELSEIF search_condition THEN statement_list] ...
[ELSE statement_list]
END IF
IF实现了一个基本的条件构造。如果search_condition求值为真,相应的SQL语句列表被执行。如果没有search_condition匹配,在ELSE子句里的语句列表被执行。statement_list可以包括一个或多个语句。2FOR语句不同FOR li_cnt IN 0..(ii_role_cnt-1) LOOP
SELECT COUNT(*) INTO li_role_ik_cnt FROM SD_ROLE
WHERE ROLE_CD = lo_aas_role_upl(li_cnt);
IF li_role_ik_cnt = 0 THEN
RETURN 'N';
END IF;
li_role_ik_cnt := -3;
END LOOP; loopLable:LOOP
IF i > (ii_role_cnt-1) THEN
LEAVE looplable;
ELSE
SELECT COUNT(*) INTO li_role_ik_cnt FROM SD_ROLE
WHERE ROLE_CD = 'ADMIN_SUPER'; /*lo_aas_role_upl(li_cnt);*/
IF li_role_ik_cnt = 0 THEN
RETURN 'N';
END IF;
SET li_role_ik_cnt = -3;
SET i = i+1;
END IF;
END LOOP loopLable;
1. oracle使用For语句实现循环.
Mysql使用Loop语句实现循环.
2. oracle 使用For…loop关键字.
Mysql使用loopLable:LOOP实现循环. 3while语句不同WHILE lv_inputstr IS NOT NULL LOOP
...
END LOOP;WHILE lv_inputstr IS NOT NULL DO
...
END WHILE;1. oracle 中使用while语句关键字为: while 表达式 loop… end loop;
mysql 中使用while语句关键字为: while 表达式 do… end while;
在MySQL中有三个标准的循环方式:WHILE循环,LOOP循环以及REPEAT循环。还有一种非标准的循环方式:GOTO,不过这种循环方式最好别用,很容易引起程序的混乱,在这里就不错具体介绍了。
这几个循环语句的格式如下:
WHILE……DO……END WHILE
REPEAT……UNTIL END REPEAT
LOOP……END LOOP
GOTO。
下面首先使用第一种循环编写一个例子。
mysql> create procedure pro10()
Query OK, 0 rows affected (0.00 sec)
mysql> delete from t1//
Query OK, 0 rows affected (0.00 sec)
mysql> call pro10()//
Query OK, 1 row affected (0.00 sec)
mysql> select * from t1//
+——-+
| filed |
+——-+
|
|
|
|
|
+——-+
5 rows in set (0.00 sec)
mysql> create procedure pro11()
Query OK, 0 rows affected (0.00 sec)
mysql> delete from t1//
Query OK, 5 rows affected (0.00 sec)
mysql> call pro11()//
Query OK, 1 row affected (0.00 sec) #虽然在这里显示只有一行数据受到影响,但是下面选择数据的话,还是插入了5行数据。
mysql> select * from t1//
+——-+
| filed |
+——-+
|
|
|
|
|
+——-+
5 rows in set (0.00 sec)
一行就是执行结果,实际的作用和使用while编写的存储过程一样,都是插入5行数据。
再来看一下第三个循环控制语句LOOP……END LOOP。编写一个存储过程程序如下:
mysql> create procedure pro12()
Query OK, 0 rows affected (0.00 sec)
从上面这个例子可以看出,使用LOOP编写同样的循环控制语句要比使用while和repeat编写的要复杂一些:在循环内部加入了IF……END IF语句,在IF语句中又加入了LEAVE语句,LEAVE语句的意思是离开循环,LEAVE的格式是:LEAVE 循环标号。
mysql> delete from t1//
Query OK, 5 rows affected (0.00 sec)
mysql> call pro12//
Query OK, 1 row affected (0.00 sec) #虽然说只有一行数据受影响,但是实际上是插入了5行数据。
mysql> select * from t1//
+——-+
| filed |
+——-+
|
|
|
|
|
+——-+
5 rows in set (0.00 sec)
mysql> create procedure pro13()
Query OK, 0 rows affected (0.00 sec)
mysql> create procedure pro14()
Query OK, 0 rows affected (0.00 sec)
ITERATE 迭代
mysql> create procedure pro15()
Query OK, 0 rows affected (0.00 sec)
mysql> delete from t1//
Query OK, 5 rows affected (0.00 sec)
mysql> call pro15//
Query OK, 1 row affected (0.00 sec)
mysql> select * from t1//
+——-+
| filed |
+——-+
|
|
|
|
+——-+
4 rows in set (0.00 sec)
和我们上面分析的结果一样,只插入了数值0,1,2,4。
- mysql循环方法总结
- java 循环方法总结
- MySQL备份方法总结
- mysql 时间方法总结
- 对跳出多层循环的方法总结
- 单向链表中循环的查找方法总结
- Java 跳出多重循环的方法总结
- Swift循环遍历集合方法总结
- MySQL修改密码方法总结
- MySQL修改密码方法总结
- MySQL修改密码方法总结
- MySQL修改密码方法总结
- MySQL修改密码方法总结
- MySQL修改密码方法总结
- MySQL修改密码方法总结
- MySQL修改密码方法总结
- MySQL修改密码方法总结
- MySQL修改密码方法总结
- Unity中NullReferenceException: (null) UnityEditor.SerializedObject..ctor (UnityEngine.Object[] 问题
- linux程序设计——进程管道(第十三章)
- jQuery插件flexigrid使用总结
- LeetCode-String to Integer (atoi) -解题报告
- MySql 存储引擎的选取
- mysql循环方法总结
- LeetCode-Reverse Integer-解题报告
- Power of Two
- poj 1811
- 有道词典Demo(WebView)
- Leetcode #27 Remove Element
- addChildViewController相关
- OSGEarth嵌入Qt的QGraphicsView框架(一)
- 【Leetcode】Find the kth in the BST