from PURE_LN.CODE_AREA C, G_GA.G_GA_M T
 where (case
         when c.area_no = '-1' then
          '1=1'
         when c.area_no <> '-1' then
          '2101'
       end)
   and c.area_no = t.area_no
如果c.area_no = '-1',形成的是where 1=1这样的查询,如果c.area_no <> '-1'则等于传进来的值。求解。

解决方案 »

  1.   

    from PURE_LN.CODE_AREA C, G_GA.G_GA_M T
     where c.area_no = '-1' and c.area_no = t.area_no
    union all
    from PURE_LN.CODE_AREA C, G_GA.G_GA_M T
     where c.area_no <> '-1 and 字段 = '2101' and c.area_no = t.area_no
      

  2.   

    from上面要查很多字段,是不是也都要再查一遍
      

  3.   

    看不懂,为啥要用case when?而且你的c.area_no <> '-1'时为什么要返回'2101'这个结果?
    化成逻辑表达式不就行了?from PURE_LN.CODE_AREA C, G_GA.G_GA_M T
     where ( c.area_no = '-1' or 字段='2101'
           )
       and c.area_no = t.area_no