这个查询好吗? [Oracle 8i]

时间:2014-02-23 21:12:30

标签: oracle oracle-sqldeveloper oracle8i

我在Oracle 11g中得到了这个查询[正常工作]:

select (case
         when seqnum = 1 then
         t.DPR_N
         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 timestamp,

       t2.APP_NAAM || '.SUBBATCH_TRIGGER' TAGNAME1

  from (select t.*,t6.*,
               row_number() over(partition by t.BATCH_ID, t.PLANT_UNIT,t6.DPR_ID order by t.BEGIN_DT) as seqnum,
               count(*) over(partition by t.BATCH_ID, t.PLANT_UNIT,t6.DPR_ID) as cnt

 FROM tb_unit_step t
INNER JOIN tb_equipment t2
ON t2.PLANT_UNIT = t.PLANT_UNIT

INNER JOIN tb_rs3 t3
ON t.BATCH_ID = t3.BATCH_ID

INNER JOIN tb_cpm t9
ON t9.BACPM_ID = t3.BACPM_ID

INNER JOIN tb_step t4
ON (t9.BV_ID    = t4.BV_ID
AND t.STAP_NR1 = t4.STAP_NR1
AND t.STAP_NR2 = t4.STAP_NR2)
INNER JOIN tb_bv t5
ON t5.BV_ID = t9.BV_ID
INNER JOIN tb_bv_process t6
ON t9.BV_ID   = t6.BV_ID
AND t6.DPR_ID = t4.DPR_ID
INNER JOIN tb_ins t7
ON (t7.INS_ID = t4.INS_ID)
INNER JOIN tb_cpm t8
ON t8.BV_ID = t9.BV_ID

 WHERE  (t.BEGIN_DT > ? AND t.END_DT < ?)
     )  t
  join tb_equipment t2 on t2.plant_unit = t.plant_unit


 where (seqnum = 1
    or seqnum = cnt);

我必须让它在Oracle 8i上工作[我知道这是一个真正的旧版本,但我别无选择,因为它不是我的数据库]。我已经构建了这个查询以便从Oracle 8i获取数据:[我为CASE WHEN更改了DECODE并删除了所有ANSI JOIN s

  SELECT DECODE(SEQNUM, 1, T.DPR_N,CNT,'0') VALUE1,
  DECODE(SEQNUM, 1, T.BEGIN_DT,CNT,T.END_DT) TIMESTAMP,

  '090.' || T2.APP_NAAM
  || '.SUBBATCH_TRIGGER' TAGNAME1
FROM
  (SELECT T.*,
    T6.*,
    ROW_NUMBER() OVER(PARTITION BY T.BATCH_ID, T.PLANT_UNIT,T6.DPR_ID ORDER BY T.BEGIN_DT) SEQNUM,
    COUNT(*) OVER(PARTITION BY T.BATCH_ID, T.PLANT_UNIT,T6.DPR_ID) CNT
  FROM tb_unit_step T ,
    tb_equipment T2 ,
    tb_rs3 T3 ,
    tb_cpm T9 ,
    tb_step T4 ,
    tb_bv T5 ,
    tb_bv_process T6 ,
    tb_ins T7 ,
    tb_cpm T8
  WHERE T2.PLANT_UNIT = T.PLANT_UNIT
  AND T.BATCH_ID      = T3.BATCH_ID
  AND (T9.BV_ID       = T4.BV_ID
  AND T.STAP_NR1      = T4.STAP_NR1
  AND T.STAP_NR2      = T4.STAP_NR2)
  AND T5.BV_ID        = T9.BV_ID
  AND (T9.BV_ID       = T6.BV_ID
  AND T6.DPR_ID       = T4.DPR_ID)
  AND T7.INS_ID       = T4.INS_ID
  AND T8.BV_ID        = T9.BV_ID
  AND (T.BEGIN_DT     > '15-jul-2013'
  AND T.END_DT       < '01-aug-2014')
  ) T
  ,tb_equipment T2  
  WHERE T2.PLANT_UNIT = T.PLANT_UNIT
  AND (T.SEQNUM         = 1
  OR SEQNUM           = T.CNT)
  ;

新查询肯定不行,因为它需要永远运行。那么从Oracle 8i获取数据的第一个查询的正确形式是什么?

更新:

查询结果:

ORA-01652: unable to extend temp segment by 128 in tablespace TEMP
01652. 00000 -  "unable to extend temp segment by %s in tablespace %s"
*Cause:    Failed to allocate an extent of the required number of blocks for
           a temporary segment in the tablespace indicated.
*Action:   Use ALTER TABLESPACE ADD DATAFILE statement to add one or more
           files to the tablespace indicated.

提前致谢!

1 个答案:

答案 0 :(得分:4)

我在Oracle 8版本中没有看到这种情况:

t9.BACPM_ID = t3.BACPM_ID

这可以解释性能问题。