-1

在 Oracle 数据库 10.2.0.1 上使用以下 SQL 时,我遇到了 oracle 错误“ORA-00933:SQL 命令未正确结束”;与 Oracle 数据库 11.1.0.7 上相同的 sql 工作正常的地方请调查并提出问题出在哪里。

提前致谢。

    SELECT concept,
            rdcno,
            rdc_mart,
            subcat,
            mart,
            artname,
            SUM (m1) m1,
            SUM (m2) m2,
            SUM (m3) m3,
            SUM (m4) m4,
            SUM (m5) m5,
            SUM (m6) m6,
            SUM (m7) m7,
            SUM (m8) m8,
            SUM (m9) m9,
            SUM (m10) m10,
            SUM (m11) m11,
            SUM (m12) m12,
            SUM (m13) m13,
            SUM (m14) m14,
            SUM (m15) m15,
            SUM (m16) m16,
            SUM (m17) m17,
            SUM (m18) m18,
            SUM (m19) m19,
            SUM (m20) m20,
            SUM (m21) m21,
            SUM (m22) m22,
            SUM (m23) m23,
            SUM (m24) m24
       FROM (  SELECT concept,
                      rdcno,
                      rdc_mart,
                      subcat,
                      mart,
                      artname,
                      month_index12,
                      index_picked,
                      SUM (deseasonalized_value) deseasonalized_value
                 FROM (SELECT concept,
                              rdcno,
                              rdcno || '-' || MART rdc_mart,
                              subcat,
                              MART,
                              ARTNAME,
                              s_ind month_index12,
                              index_picked,
                              NVL (deseasonalized_value, 0) deseasonalized_value
                         FROM (SELECT s.concept,
                                      s.rdcno,
                                      s.subcat "SUBCAT",
                                      s.mart "MART",
                                      s."ARTNAME",
                                      s."YEAR",
                                      s."BMONTH",
                                      s."PAIRS",
                                      s."VALUE",
                                      i."MONTH_INDEX",
                                      s.month_index s_ind,
                                      i.seasonal_index,
                                      i.index_picked,
                                      CASE
                                         WHEN i.seasonal_index IS NULL
                                              OR i.seasonal_index = 0
                                         THEN
                                            0
                                         ELSE
                                            ROUND (
                                               (CASE
                                                   WHEN s.pairs < 0 THEN 0
                                                   ELSE s.pairs
                                                END)
                                               / i.seasonal_index,
                                               5)
                                      END
                                         deseasonalized_value
                                 FROM ps_sales_data s, ps_seasonal_index i
                                WHERE     i.concept(+) = s.concept
                                      AND i.rdcno(+) = s.rdcno
                                      AND i.subcat(+) = s.subcat
                                      AND (i.month_index = s.month_index
                                           OR i.month_index + 12 = s.month_index)))
             GROUP BY concept,
                      rdcno,
                      rdc_mart,
                      subcat,
                      mart,
                      artname,
                      month_index12,
                      index_picked) PIVOT (MAX (deseasonalized_value)
                                    FOR month_index12
                                    IN  (1 AS M1,
                                        2 AS M2,
                                        3 AS M3,
                                        4 AS M4,
                                        5 AS M5,
                                        6 AS M6,
                                        7 AS M7,
                                        8 AS M8,
                                        9 AS M9,
                                        10 AS M10,
                                        11 AS M11,
                                        12 AS M12,
                                        13 AS M13,
                                        14 AS M14,
                                        15 AS M15,
                                        16 AS M16,
                                        17 AS M17,
                                        18 AS M18,
                                        19 AS M19,
                                        20 AS M20,
                                        21 AS M21,
                                        22 AS M22,
                                        23 AS M23,
                                        24 AS M24))
   GROUP BY concept,
            rdcno,
            rdc_mart,
            subcat,
            mart,
            artname;
4

1 回答 1

3

据我所知,pivot 是 11g 中的一个新特性:

http://psoug.org/reference/ora_operators.html#oppv

但是在 11g 之前如何做同样的事情有一个很长的话题:

http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:766825833740

于 2013-10-29T09:22:48.267 回答