ORA-00933: SQL command not properly ended in subquery with join

只谈情不闲聊 提交于 2019-12-11 02:27:53

问题


It's been a while for me since the last time I did Oracle SQL, hope someone can tell me why I get a 933 on:

   SELECT TRIM(A.ACCOUNTNUMBER) AS INDBDebnmbr
, TRIM(A.VOUCHER) AS INinvoicenmbr
, A.DATE_ AS INinvoiceDate
, A.DUEDATE AS INinvoiceDueDate
, A.TXT AS INDescription
, A.EXCHANGECODE AS INCurrencyCode
, subq.AMOUNTMST AS INOriginalamount
, subq.SETTLEAMOUNTMST AS INpaidAmount
, subq.OPENAMOUNT AS INOpenAmount
FROM (
  SELECT DEBTRANS.VOUCHER AS VOUCHER, SUM(DEBTRANS.AMOUNTMST) AS AMOUNTMST
  , SUM(DEBTRANS.SETTLEAMOUNTMST) AS SETTLEAMOUNTMST
  , SUM(DEBTRANS.AMOUNTMST - DEBTRANS.SETTLEAMOUNTMST) AS OPENAMOUNT
  FROM XAL_SUPERVISOR.DEBTRANS DEBTRANS 
  WHERE DEBTRANS.OPEN = 1 AND
  DEBTRANS.TRANSTYPE <> 9 AND
  (DEBTRANS.AMOUNTMST - DEBTRANS.SETTLEAMOUNTMST) <> 0 AND
  DEBTRANS.DATASET = 'FIK'
  GROUP BY DEBTRANS.VOUCHER) subq INNER JOIN DEBTRANS A ON A.VOUCHER = subq.VOUCHER

In SQL Plus Thanks in advance,

Michael


回答1:


Your comment about using 8i explains it. The ANSI '92 Join syntax was not implemented in Oracle until 9i.

You will need to modify your query:

       SELECT TRIM(A.ACCOUNTNUMBER) AS INDBDebnmbr
    , TRIM(A.VOUCHER) AS INinvoicenmbr
    , A.DATE_ AS INinvoiceDate
    , A.DUEDATE AS INinvoiceDueDate
    , A.TXT AS INDescription
    , A.EXCHANGECODE AS INCurrencyCode
    , subq.AMOUNTMST AS INOriginalamount
    , subq.SETTLEAMOUNTMST AS INpaidAmount
    , subq.OPENAMOUNT AS INOpenAmount
    FROM (
      SELECT DEBTRANS.VOUCHER AS VOUCHER, SUM(DEBTRANS.AMOUNTMST) AS AMOUNTMST
      , SUM(DEBTRANS.SETTLEAMOUNTMST) AS SETTLEAMOUNTMST
      , SUM(DEBTRANS.AMOUNTMST - DEBTRANS.SETTLEAMOUNTMST) AS OPENAMOUNT
      FROM XAL_SUPERVISOR.DEBTRANS DEBTRANS 
      WHERE DEBTRANS.OPEN = 1 AND
      DEBTRANS.TRANSTYPE <> 9 AND
      (DEBTRANS.AMOUNTMST - DEBTRANS.SETTLEAMOUNTMST) <> 0 AND
      DEBTRANS.DATASET = 'FIK'
      GROUP BY DEBTRANS.VOUCHER) subq,
      DEBTRANS A
 WHERE A.VOUCHER = subq.VOUCHER;



回答2:


What is the DEBTRANS you're joining to, is it another instance of XAL_SUPERVISOR.DEBTRANS? If so, please don't use DEBTRANS as an alias in the subquery, it is confusing. Change it to something else and try again, e.g.

 SELECT TRIM(A.ACCOUNTNUMBER) AS INDBDebnmbr
, TRIM(A.VOUCHER) AS INinvoicenmbr
, A.DATE_ AS INinvoiceDate
, A.DUEDATE AS INinvoiceDueDate
, A.TXT AS INDescription
, A.EXCHANGECODE AS INCurrencyCode
, subq.AMOUNTMST AS INOriginalamount
, subq.SETTLEAMOUNTMST AS INpaidAmount
, subq.OPENAMOUNT AS INOpenAmount
FROM (
  SELECT dt.VOUCHER AS VOUCHER
  , SUM(dt.AMOUNTMST) AS AMOUNTMST
  , SUM(dt.SETTLEAMOUNTMST) AS SETTLEAMOUNTMST
  , SUM(dt.AMOUNTMST - dt.SETTLEAMOUNTMST) AS OPENAMOUNT
  FROM XAL_SUPERVISOR.DEBTRANS dt
  WHERE dt.OPEN = 1 AND
  dt.TRANSTYPE <> 9 AND
  (dt.AMOUNTMST - dt.SETTLEAMOUNTMST) <> 0 AND
  dt.DATASET = 'FIK'
  GROUP BY dt.VOUCHER) subq INNER JOIN DEBTRANS A ON A.VOUCHER = subq.VOUCHER



回答3:


Instead of the last line of

INNER JOIN DEBTRANS A ON A.VOUCHER = subq.VOUCHER

use

INNER JOIN DEBTRANS A ON A.VOUCHER = subq.INinvoicenmbr



来源:https://stackoverflow.com/questions/6358057/ora-00933-sql-command-not-properly-ended-in-subquery-with-join

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!