SQL命令未正确结束

时间:2016-05-19 05:55:39

标签: sql oracle plsql

SELECT SUM(nvl(DYRCVDWT, 0)) + SUM(nvl(RCVDWT, 0)) + SUM(nvl(rcvdafpwt, 0)) - SUM(nvl(retdwt, 0)) INTO netwt
FROM YARNLEDGER yl
(SELECT D.PROFILECODE, MAX(CLOSINGDATE)SDATE FROM PARTYSTOCKCLOSING D WHERE D.DEPT = 'Y' AND NVL(D.POSTED, 'N') = 'Y' GROUP BY D.PROFILECODE) SAD
WHERE yl.PROFILECODE = :PROFILECODE 

AND Yl.PROFILECODE = SAD.PROFILECODE(+)
AND Yl.DOCUMENTDATE>SAD.SDATE 

1 个答案:

答案 0 :(得分:1)

在" yarnledger yl"

之后,FROM中缺少一个逗号
SELECT SUM(nvl(dyrcvdwt, 0)) + SUM(nvl(rcvdwt, 0)) + SUM(nvl(rcvdafpwt, 0)) - SUM(nvl(retdwt, 0))
  INTO netwt
  FROM yarnledger yl ,(SELECT d.profilecode
                            ,MAX(closingdate) sdate
                        FROM partystockclosing d
                       WHERE d.dept = 'Y'
                         AND nvl(d.posted, 'N') = 'Y'
                       GROUP BY d.profilecode) sad
 WHERE yl.profilecode = :profilecode      
   AND yl.profilecode = sad.profilecode(+)
   AND yl.documentdate > sad.sdate

下次使用更清晰的查询结构:

WITH sad as (SELECT d.profilecode
                   ,MAX(closingdate) sdate
               FROM partystockclosing d
              WHERE d.dept = 'Y'
                AND nvl(d.posted, 'N') = 'Y'
              GROUP BY d.profilecode)  


SELECT SUM(nvl(dyrcvdwt, 0)) + SUM(nvl(rcvdwt, 0)) + SUM(nvl(rcvdafpwt, 0)) - SUM(nvl(retdwt, 0))
  INTO netwt
  FROM yarnledger yl
  LEFT OUTER JOIN sad
    ON yl.profilecode = sad.profilecode 
   AND yl.documentdate > sad.sdate   
 WHERE yl.profilecode = :profilecode