选择查询成功但是使用相同查询的插入失败并且ORA-00979(不是GROUP BY表达式)

时间:2017-09-09 10:09:14

标签: oracle group-by ora-00979

我很难找到为什么下面的插入在单独执行select时会失败。

INSERT INTO I6_POC_ADJ_OUTPUT
(LOADID,ADJ_ID,ADJ_CATEGORY,ADJ_COMMENT,ITEM,CHANNEL,FDATE,ADJ_TOT_QTY,FQTY)
SELECT 
    ADJ.LOADID,ADJ.ADJ_ID,ADJ.ADJ_CATEGORY,ADJ.ADJ_COMMENT,ADJ.ITEM,ADJ.CHANNEL,ADJ.FDATE,MAX(ADJ.FQTY) ADJ_TOT_QTY,
    SUM(ADJ.TP_SPLIT) FQTY
FROM I3_POC_ADJ_INPUT  ADJ,V_POC_HIST_BASE BASE
WHERE ADJ.ITEM=BASE.ITEM(+) AND ADJ.CHANNEL=BASE.CHANNEL(+) AND ADJ.FDATE=BASE.FDATE(+) 
AND ADJ.LOADID=71 AND ADJ.ITEM='10-56-034' AND ADJ.CHANNEL='CH1820' AND ADJ.FDATE=DATE'2017-09-03'
GROUP BY ADJ.LOADID,ADJ.ADJ_ID,ADJ.ADJ_CATEGORY,ADJ.ADJ_COMMENT,ADJ.ITEM,ADJ.CHANNEL,ADJ.FDATE;

Select and Insert Executions

更新

尝试使用简单的CTAS并且有效。

CREATE TABLE TEST_ADJ_OUTPUT AS
SELECT * FROM (
 SELECT 
 ADJ.LOADID,ADJ.ADJ_ID,ADJ.ADJ_CATEGORY,ADJ.ADJ_COMMENT,ADJ.ITEM,ADJ.CHANNEL,ADJ.FDATE,MAX(ADJ.FQTY),
 SUM(ADJ.FQTY*ADJ.TP_SPLIT)
 FROM I3_POC_ADJ_INPUT  ADJ,V_POC_HIST_BASE BASE
 WHERE ADJ.ITEM=BASE.ITEM(+) AND ADJ.CHANNEL=BASE.CHANNEL(+) AND ADJ.FDATE=BASE.FDATE(+) 
 AND ADJ.LOADID=71 AND ADJ.ITEM='10-56-034' AND ADJ.CHANNEL='CH1820' AND ADJ.FDATE=DATE'2017-09-03'
 GROUP BY ADJ.LOADID,ADJ.ADJ_ID,ADJ.ADJ_CATEGORY,ADJ.ADJ_COMMENT,ADJ.ITEM,ADJ.CHANNEL,ADJ.FDATE
);

截断同一个表并尝试插入相同但如果失败并出现相同的错误。 " SQL错误:ORA-00979:不是GROUP BY表达式"

TRUNCATE TABLE TEST_ADJ_OUTPUT;
INSERT INTO TEST_ADJ_OUTPUT
SELECT * FROM (
 SELECT 
 ADJ.LOADID,ADJ.ADJ_ID,ADJ.ADJ_CATEGORY,ADJ.ADJ_COMMENT,ADJ.ITEM,ADJ.CHANNEL,ADJ.FDATE,MAX(ADJ.FQTY),
 SUM(ADJ.FQTY*ADJ.TP_SPLIT)
 FROM I3_POC_ADJ_INPUT  ADJ,V_POC_HIST_BASE BASE
 WHERE ADJ.ITEM=BASE.ITEM(+) AND ADJ.CHANNEL=BASE.CHANNEL(+) AND ADJ.FDATE=BASE.FDATE(+) 
 AND ADJ.LOADID=71 AND ADJ.ITEM='10-56-034' AND ADJ.CHANNEL='CH1820' AND ADJ.FDATE=DATE'2017-09-03'
 GROUP BY ADJ.LOADID,ADJ.ADJ_ID,ADJ.ADJ_CATEGORY,ADJ.ADJ_COMMENT,ADJ.ITEM,ADJ.CHANNEL,ADJ.FDATE
);

感谢您的帮助。

谢谢, 的Manoj

0 个答案:

没有答案