• SQL语句嵌套if


    在存储过程中我要实现一个IF的嵌套语句查询,类似与
    if()
    {
        if()
         {
            ......
         }
         else
         {
            ......
         }
    }
    else
    {
        ......
    }
    请问这样的SQL语句要怎么写啊?

    create procedure `test2`
    (
    IN cusername <a href="https://www.baidu.com/s?wd=VARCHAR&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1dWPj6knWw9PvDzPAc4nH0z0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6K1TL0qnfK1TL0z5HD0IgF_5y9YIZ0lQzqlpA-bmyt8mh7GuZR8mvqVQL7dugPYpyq8Q1D3rjnYnWbYnHDzPjmzrHTkPj6" target="_blank" class="baidu-highlight">VARCHAR</a>(50),
    IN cpassword <a href="https://www.baidu.com/s?wd=VARCHAR&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1dWPj6knWw9PvDzPAc4nH0z0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6K1TL0qnfK1TL0z5HD0IgF_5y9YIZ0lQzqlpA-bmyt8mh7GuZR8mvqVQL7dugPYpyq8Q1D3rjnYnWbYnHDzPjmzrHTkPj6" target="_blank" class="baidu-highlight">VARCHAR</a>(50),
    IN clastloginio <a href="https://www.baidu.com/s?wd=VARCHAR&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1dWPj6knWw9PvDzPAc4nH0z0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6K1TL0qnfK1TL0z5HD0IgF_5y9YIZ0lQzqlpA-bmyt8mh7GuZR8mvqVQL7dugPYpyq8Q1D3rjnYnWbYnHDzPjmzrHTkPj6" target="_blank" class="baidu-highlight">VARCHAR</a>(50)
    )
    BEGIN  
        if exists(select from mt_userlogin where username=cusername) then
    --    if exists(select 1) then
            if(1=1) THEN
                select 1;
            <a href="https://www.baidu.com/s?wd=ELSE&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1dWPj6knWw9PvDzPAc4nH0z0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6K1TL0qnfK1TL0z5HD0IgF_5y9YIZ0lQzqlpA-bmyt8mh7GuZR8mvqVQL7dugPYpyq8Q1D3rjnYnWbYnHDzPjmzrHTkPj6" target="_blank" class="baidu-highlight">ELSE</a>
                select 2;
            end if;
        <a href="https://www.baidu.com/s?wd=ELSE&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1dWPj6knWw9PvDzPAc4nH0z0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6K1TL0qnfK1TL0z5HD0IgF_5y9YIZ0lQzqlpA-bmyt8mh7GuZR8mvqVQL7dugPYpyq8Q1D3rjnYnWbYnHDzPjmzrHTkPj6" target="_blank" class="baidu-highlight">ELSE</a>  
            select -7,'Username not found';
        end if;
    end;
  • 相关阅读:
    hdu 1593 find a way to escape
    bzoj4561: [JLoi2016]圆的异或并
    hdu 3511 Prison Break
    hdu 5299 Circles Game
    ORA-15025: could not open disk "/dev/asm***"--转载
    修改目的端trail文件的最大大小--转载
    MYSQL PERFORMANCE_SCHEMA HINTS
    Oracle 收缩表大小 Oracle Shrink Table --转载
    InnoDB: Error number 24 means ‘Too many open files’.--转载
    使用asmcmdcp命令把datafile从文件系统移动(move)到asm磁盘组中 针对11gR2
  • 原文地址:https://www.cnblogs.com/caicaizi/p/4941365.html
Copyright © 2020-2023  润新知