您好,欢迎访问一九零五行业门户网

MySql存储过程―6、循环_MySQL

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
其它类似信息

推荐信息