我在Oracle数据库10.2.0.1上使用下面的SQL时遇到oracle错误“ORA-00933:SQL命令未正确结束”;同样的SQL在Oracle Database 11.1.0.7上正常工作 请注意并查看问题所在。
提前致谢。
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;
答案 0 :(得分: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