oracle中游标的where条件中可以有case when 语句吗,具体写法是什么?

daijingbo1987 2011-12-20 10:49:53
例如:
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语句?

急啊,麻烦各位了!
...全文
707 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
oracle中DECODE这个函数作用很大 一般用到case语句中
forgetsam 2011-12-21
  • 打赏
  • 举报
回复
你根本就没弄明白,你说的是动态拼接。
zujinsheng 2011-12-20
  • 打赏
  • 举报
回复
where .. and v.catalog not like (case when ..)
a120255857 2011-12-20
  • 打赏
  • 举报
回复
你後面case when 只是取一個值啊。where 是要跟條件的。
daijingbo1987 2011-12-20
  • 打赏
  • 举报
回复
自己顶
我心飞翔 2011-12-20
  • 打赏
  • 举报
回复
语法有问题,请参考:

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;
daijingbo1987 2011-12-20
  • 打赏
  • 举报
回复
就是判断输入参数是‘建筑’时,让where条件为v.catalog not like '%设备%' and v.catalog not like '%材料%'

17,082

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧