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

解决方案 »

  1.   


     在存储过程中if后面是没有括号的。
      用begin和end来代替括号。
      把你要写的语句写在begin和end之间。
     上面的问题看你要写怎么样的。
      

  2.   

    select case when data1 = 'a' then 1 when data1='b' then 2 else 0 end from dual;
    oracle中还有decode()函数
    是你要的语法?
      

  3.   

    case when data1 = 'a' and data2='c' then 1 when data1='b' then 2 else 0 end case语句和decode都可以嵌套使用
      

  4.   

    if 1=1
    begin
      print '1'
    end
      

  5.   

    if(@a == 'xxxx') 
    BEGIN
        if(@B == 'XXXXXXXXXXX') 
         BEGIN
              .........
        END
        else 
        BEGIN
             .........
        END 
    END 
    else
    BEGIN 
        ...... 
    END
      

  6.   

    if()
     begin
      if()
       begin
        `````
       end
       else
       begin
        ```
        end  
     end
    else
     begin
     `````
     end