在连接条件中使用时语句在 oracle 中不起作用的情况

Case when statement while using in join condition not working in oracle

我需要在尝试 sql.I 中的连接语句时使用 case,但出现错误:

Missing expression:ORA-00905

我试过这个查询:

SELECT * 
FROM   abc a 
       LEFT JOIN (SELECT * 
                  FROM   anil_groups 
                  WHERE  datatype = 'C' 
                         AND payor = 'SELECT') gr 
              ON CASE 
                   WHEN Upper(a.sourcefilename) LIKE '%RIO%' THEN 
                   gr.sourceid = 'SH_Rio_Tinto' 
                   ELSE gr.sourceid = 'SH_Albertson' 
                 END 
       LEFT JOIN (SELECT * 
                  FROM   tbl_danger 
                  WHERE  source = 'KK') spec 
              ON Upper(a.rollupid) = spec.code; 

在 oracle 中不是那样工作的。 CASE WHEN 是一个提供非布尔值的构造,因此您必须将它用于 运行 您的布尔测试 (Upper(a.sourcefilename) LIKE '%RIO%') 并让它生成要与 [=13= 进行比较的字符串值]:

ON gr.sourceid = CASE 
                   WHEN Upper(a.sourcefilename) LIKE '%RIO%' THEN 
                    'SH_Rio_Tinto' 
                   ELSE 'SH_Albertson' 
                 END 

您也可以重写您的联接以不使用它:

ON (gr.sourceid = 'SH_Rio_Tinto' AND Upper(a.sourcefilename) LIKE '%RIO%') OR
   (gr.sourceid = 'SH_Albertson' AND Upper(a.sourcefilename) NOT LIKE '%RIO%')