Query works on Oracle 11g but fails on Oracle 8i

好久不见. 提交于 2019-12-20 06:29:25

问题


I am running this query in Oracle 11g with no problem:

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');

But when I run it in Oracle 8i (8.7.1) it gives ORA-00933: SQL command not properly ended.

Is there anys special consideration I must know for running sql commands in Oracle 8i?

Thanks in advance


回答1:


AFAK case command was introduced since 9i.




回答2:


OK - trip--down-memory-lane time:

select decode(seqnum,
                1,    '1',
                cnt,  '0') as value1,
       decode(seqnum,
                1,    t.BEGIN_DT,
                cnt,  t.END_DT) 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
          INNER join (select ID1, batch_id
                        from SCH2.VW_BATCH) t2
            on t.BATCH_ID = t2.BATCH_ID
          INNER join (select ID2, ID1
                        from SCH1.STEP) t3
            on t3.ID1 = t2.ID1) t
  INNER 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');


来源:https://stackoverflow.com/questions/21773284/query-works-on-oracle-11g-but-fails-on-oracle-8i

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!