本文介绍了Oracle 8i中CASE的替代品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

感谢stackoverflow社区,我发现由于CASE WHEN,Oracle 8i不支持此查询.

Thanks to the stackoverflow community I found out that this query is not supported in Oracle 8i because of the CASE WHEN.

select (case
         when seqnum = 1 then
          '1'
         when seqnum = cnt then
          '0'
       end) as value1,
       (case
         when seqnum = 1 then
          t.BEGIN_DT
         when seqnum = cnt then
          t.END_DT
       end) as TIME1,      
       t4.UNIT1 || '.SUBBATCH_TRIGGER' TAG     
  from (select t.*,
               row_number() over(partition by t.BATCH_ID, t.plant_unit, t3.ID2 order by t.BEGIN_DT) as seqnum,
               count(*) over(partition by t.BATCH_ID, t.plant_unit, t3.ID2) as cnt
          from SCH2.tb_pg_unit_stap t
join (select ID1,batch_id from SCH2.VW_BATCH) t2 on t.BATCH_ID = t2.BATCH_ID
join (select ID2,ID1 from SCH1.STEP) t3 on t3.ID1 = t2.ID1) t
join SCH2.TB_W_MACHINE t4 on t4.plant_unit = t.plant_unit
where (seqnum = 1
    or seqnum = cnt) AND (t.BEGIN_DT > '01-jan-2013' AND t.BEGIN_DT < '01-feb-2013');

在Oracle 8i上运行此查询有哪些替代方案?

What are the alternatives for this query to run on Oracle 8i?

提前谢谢!

推荐答案

您应该尝试使用decode(..., ..., ...)

select
  decode(seqnum,
            1  , '1',
            cnt, '0'
        ) as                   value1,
  decode(seqnum,
            1  , t.BEGIN_DT,
            cnt, t.END_DT
  ) as                         TIME1
  ...

此处是链接解码的文档.

但是,正如评论中指出的那样,join构造( ansi joins )在8i中也不起作用.

However, as has been pointed out in a comment, the join construct (ansi joins) won't work in 8i either.

这篇关于Oracle 8i中CASE的替代品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 04:42