zoukankan      html  css  js  c++  java
  • 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;
  • 相关阅读:
    软件总结
    今日总结
    今日总结
    今日总结
    今日总结
    今日总结
    今日总结
    3.22
    3.21
    3.20
  • 原文地址:https://www.cnblogs.com/caicaizi/p/4941365.html
Copyright © 2011-2022 走看看