• 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;
  • 相关阅读:
    zoj 3715 K
    bzoj 2002(弹飞绵羊) 分块
    最大01矩阵(悬线法)
    csu 1809 Parenthesis(线段树)
    csu 1804(有向无环图)
    csu 1803(2016)
    RCC 2017 Qual 1 Mail.Ru, April 2, 2017 Problem C. Magic Artifact
    Unmarshaller解析xml文件
    sax解析xml文件,封装到对象中
    cas环境搭建
  • 原文地址:https://www.cnblogs.com/caicaizi/p/4941365.html
Copyright © 2020-2023  润新知