例如:
cursor cur_dalei(dalei in varchar2) is
select a.id,v.catalog
from bom a,cux b
where a.id=b.id
and (case when dalei is null then null end
case when dalei='设备' then v.catalog not like '%材料%' and v.catalog not like '%建筑%' end 
case when dalei='材料' then v.catalog not like '%设备%' and v.catalog not like '%建筑%' end
case when dalei='建筑' then v.catalog not like '%设备%' and v.catalog not like '%材料%' end)
order by a.id;这样执行不下去,语法有错误吗?还是cursor根本就不支持where条件后加case when语句?急啊,麻烦各位了!

解决方案 »

  1.   

    你後面case when 只是取一個值啊。where 是要跟條件的。
      

  2.   

    where .. and v.catalog not like (case when ..)
      

  3.   

    就是判断输入参数是‘建筑’时,让where条件为v.catalog not like '%设备%' and v.catalog not like '%材料%'
      

  4.   

    语法有问题,请参考:cursor cur_dalei(dalei in varchar2) is
    select a.id,v.catalog
    from bom a,cux b
    where a.id=b.id
    and v.catalog NOT LIKE 
    DECODE(dalei, '设备', '%材料%建筑%', '材料', '%设备%建筑%', '建筑', '%设备%材料%')
    order by a.id;
      

  5.   

    oracle中DECODE这个函数作用很大  一般用到case语句中