这有什么错误:ORA-00933:SQL命令没有正确结束

时间:2016-04-05 06:20:36

标签: sql oracle

SELECT CU.CUST_CODE
FROM AR_CUSTOMERS CU
WHERE CU.CUST_CODE=TM.CUST_CODE
UNION
SELECT ITS.ITEMS_CODE
FROM AR_ITEMS ITS
WHERE ITS.ITEMS_CODE = TD.ITEM_CODE
UNION
SELECT ITS.ITEMS_NAME
FROM AR_ITEMS ITS
WHERE TM.INVOICE_NO = TD.INVOICE_NO AND ITS.ITEMS_CODE = TD.ITEM_CODE
UNION
SELECT TO_CHAR(TM.JOB_DATE,'MON-YY')MON, TO_CHAR(TM.JOB_DATE,'MM-YY')MM
FROM AR_TRANS_MASTER TM
SELECT SUM(TD.QUANTITY)QUANTITY, SUM(TD.PRICE)UNIT
FROM AR_TRANS_DETAIL TD
WHERE ITS.ITEMS_CODE = TD.ITEM_CODE
TM.JOB_DATE  :STARTDATE AND :STOPDATE
GROUP BY 
CU.CUST_CODE,ITS.ITEMS_CODE,ITS.ITEMS_NAME,TO_CHAR(TM.JOB_DATE,'MON-YY'),TO_CHAR(TM.JOB_DATE,'MM-YY')
ORDER BY
MM ASC

让我知道这是错误是什么,任何人都可以解释或纠正

  
      
  1. 00000 - " SQL命令未正确结束"
      *原因:
      *操作:
      行错误:15列:1
  2.   

在(工会)MADE的这次修正之后,现在存在错误:

ORA-00904:" TM"。" CUST_CODE":无效的标识符 00904. 00000 - "%s:无效标识符" *原因:
*行动: 行错误:3列:22

如何找到这个

3 个答案:

答案 0 :(得分:1)

也许,第15行缺少UNION

SELECT CU.CUST_CODE
FROM AR_CUSTOMERS CU
WHERE CU.CUST_CODE=TM.CUST_CODE
UNION
SELECT ITS.ITEMS_CODE
FROM AR_ITEMS ITS
WHERE ITS.ITEMS_CODE = TD.ITEM_CODE
UNION
SELECT ITS.ITEMS_NAME
FROM AR_ITEMS ITS
WHERE TM.INVOICE_NO = TD.INVOICE_NO AND ITS.ITEMS_CODE = TD.ITEM_CODE
UNION
SELECT TO_CHAR(TM.JOB_DATE,'MON-YY')MON, TO_CHAR(TM.JOB_DATE,'MM-YY')MM
FROM AR_TRANS_MASTER TM
UNION
SELECT SUM(TD.QUANTITY)QUANTITY, SUM(TD.PRICE)UNIT
FROM AR_TRANS_DETAIL TD
WHERE ITS.ITEMS_CODE = TD.ITEM_CODE
TM.JOB_DATE  :STARTDATE AND :STOPDATE
GROUP BY 
CU.CUST_CODE,ITS.ITEMS_CODE,ITS.ITEMS_NAME,TO_CHAR(TM.JOB_DATE,'MON-   YY'),TO_CHAR(TM.JOB_DATE,'MM-YY')
ORDER BY
MM ASC

答案 1 :(得分:0)

看起来你错过了一个' UNION' (或任何其他预期的运营商)这些行之间:

FROM AR_TRANS_MASTER TM
SELECT SUM(TD.QUANTITY)QUANTITY, SUM(TD.PRICE)UNIT

您可能打算:

SELECT CU.CUST_CODE
FROM AR_CUSTOMERS CU
WHERE CU.CUST_CODE=TM.CUST_CODE
UNION
SELECT ITS.ITEMS_CODE
FROM AR_ITEMS ITS
WHERE ITS.ITEMS_CODE = TD.ITEM_CODE
UNION
SELECT ITS.ITEMS_NAME
FROM AR_ITEMS ITS
WHERE TM.INVOICE_NO = TD.INVOICE_NO AND ITS.ITEMS_CODE = TD.ITEM_CODE
UNION
SELECT TO_CHAR(TM.JOB_DATE,'MON-YY')MON, TO_CHAR(TM.JOB_DATE,'MM-YY')MM
FROM AR_TRANS_MASTER TM
UNION
SELECT SUM(TD.QUANTITY)QUANTITY, SUM(TD.PRICE)UNIT
FROM AR_TRANS_DETAIL TD
WHERE ITS.ITEMS_CODE = TD.ITEM_CODE
TM.JOB_DATE  :STARTDATE AND :STOPDATE
GROUP BY 
CU.CUST_CODE,ITS.ITEMS_CODE,ITS.ITEMS_NAME,TO_CHAR(TM.JOB_DATE,'MON-YY'),TO_CHAR(TM.JOB_DATE,'MM-YY')
ORDER BY
MM ASC

答案 2 :(得分:0)

我认为你在结合的情况下,你不能在一个查询中使用引用名称到另一个查询 示例

  select a.col1 from tab1 a where a.col1=b.col2
  union
  select b.col2 from tab2 b;

b是查询2中表的引用,我认为它不能用于查询1.请检查