SELECT子句中的Oracle SQL CASE语句不起作用

时间:2018-08-31 21:33:31

标签: sql oracle oracle11g

运行以下CASE语句时得到的结果好坏参半。

我想做的是基于

识别维修类型

1)零件编号的一部分,以及 2)与零件号关联的部分劳动代码。

该语句似乎适用于称为“ REPLACED”的语句,但当零件号和/或人工代码混合时,则无效。在大多数情况下,它们以“ OTHER”结尾。

CASE语句按修复重要性顺序编写。我的结构有问题吗?我不是在问正确的问题吗?

(CASE 
 WHEN (D.PART_NO LIKE '3102%') AND (F.OPER_CD = 'JD01AA') THEN 'REPLACED'
 WHEN (D.PART_NO LIKE '310C%') AND (F.OPER_CD = 'JD01AA') THEN 'REPLACED'
 WHEN (D.PART_NO LIKE '3103%') AND (F.OPER_CD = 'JD01AA') THEN 'REPLACED'
 WHEN (D.PART_NO LIKE '310F%') AND (F.OPER_CD = 'JD01AA') THEN 'REPLACED'
 WHEN (D.PART_NO LIKE '3110%') THEN 'TCONVERT'
 WHEN (D.PART_NO LIKE '3121%') THEN 'AFR'
 WHEN (D.PART_NO LIKE '31490%') THEN 'GEAR_RDC'
 WHEN (D.PART_NO LIKE '31495%') THEN 'GEAR_RDC'
 WHEN (D.PART_NO LIKE '3170%') AND (F.OPER_CD = 'JD48AA') THEN 'CVALVE'
 WHEN (D.PART_NO LIKE '3834%') OR (F.OPER_CD IN ('JD64AA', 'JD65AA', 'JD66AA')) THEN 'DSEAL'
 WHEN (D.PART_NO LIKE '3137%') OR (F.OPER_CD ='JD88AA') THEN 'TCSEAL'
 WHEN (D.PART_NO LIKE '3311%') OR (F.OPER_CD ='JD88AA') THEN 'TCSEAL'
 WHEN (D.PART_NO LIKE '3170%') AND (F.OPER_CD = 'JD48AA') THEN 'CVALVE'
 WHEN (D.PART_NO LIKE '31490%') THEN 'GEAR_RDC'
 WHEN (D.PART_NO LIKE '31495%') THEN 'GEAR_RDC'
 WHEN (F.OPER_CD LIKE 'NODJD%') THEN 'NDF'
 WHEN (COUNT(D.PART_NO) < '1') THEN 'REPROGM'
     ELSE ('OTHER')
     END) RPRTYP 

有人可以协助吗?

0 个答案:

没有答案