zoukankan      html  css  js  c++  java
  • if-case-循环语句

    IF语句

    drop procedure if exists p_hello_world;  
    create procedure p_hello_world(in v_id int)  
    begin  
        if (v_id > 0) then  
            select '> 0';  
        elseif (v_id = 0) then  
            select '= 0';  
        else  
            select '< 0';  
        end if;  
    end;  
    call p_hello_world(-9);  

    Case语句

    drop procedure if exists pro2;
    delimiter //
    create procedure pro2(in tid int(10))
    begin 
        case tid
            when 1 then
                insert into test values(1,'xjh','tx','15268335587');
            when 2 then 
                insert into test values(2,'zjj','tx','15268335587');
        end case;
    end//
    delimiter ;

    如果case中未处理的参数则会报 Case not found for CASE statement 错误

    循环

      WHILE-DO…END-WHILE循环

    delimiter //
    create procedure pro2()
    begin 
        set  @i = 0;
        while @i<10 do
            insert into test (tid,tname)values(@i,'批量');
            set @i=@i+1;
        end while;
    end//
    delimiter ;

      REPEAT...END REPEAT

    delimiter //
    create procedure pro2()
    begin 
        set  @i = 0;
        repeat
            insert into test (tid,tname)values(@i,'批量');
            set @i = @i + 1;
        UNTIL @i< 10 end repeat;
    end//
    delimiter ;

      LOOP...END LOOP

    delimiter //
    create procedure pro2()
    begin 
        set  @i = 0;
        loop_pos:loop
            insert into test (tid,tname)values(@i,'批量');
            set @i = @i + 1;
            if @i =2 then
                leave loop_pos;
            end if;
        end loop;
    end//
    delimiter ;
  • 相关阅读:
    AJAX 跨域请求与 JSONP详解
    深入理解PHP的mvc框架
    读文文件md5值
    快速排序
    编写简单GUI程序
    简单的加减法
    rallway.py
    用列表构建栈结构
    模拟用户登陆注册
    密码生成
  • 原文地址:https://www.cnblogs.com/FlyBlueSky/p/8641025.html
Copyright © 2011-2022 走看看