您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

MySql存储过程―6、循环_MySQL

2024/2/20 8:20:19发布16次查看
bitscn.com
mysql存储过程—6、循环 相关链接:mysql存储过程—1、sql存储过程的基础知识http:///database/201208/148790.html;mysql存储过程—2、第一个mysql存储过程的建立http:///database/201208/148791.html;mysql存储过程—3、变量http:///database/201208/149069.html;mysql存储过程—4、参数http:///database/201208/149113.html;mysql存储过程—5、逻辑判断,条件控制http:///database/201208/149282.html 在mysql的存储过程中可使用的循环有三种:while、repeat、loop 1、while while的格式是这样的:[sql] while expression do     statements  end while  下面是个例子[sql] delimiter $$       drop procedure if exists `test`.`whileloopproc` $$  create procedure `test`.`whileloopproc` ()  begin   declare x  int;   declare str  varchar(255);   set x = 1;   set str =  '';   while x   10 then     leave  loop_label;    end  if;    set  x = x + 1;    if  (x mod 2) then     iterate  loop_label;    else         set  str = concat(str,x,',');    end  if;    end loop;  select str;  end $$    delimiter ;  上面代码输出10以内的偶数,用逗号分隔。这里注意到x>10的时候就leave掉,如果遇到奇数则iterate,奇数对2取模为1,表示true bitscn.com
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product