2013-01-21 77 views
-1

該查詢的註釋(/ * * /)部分執行,但是整個查詢在///////部分出現問題。請高手解決此問題。Oracle內嵌視圖查詢

SELECT * 
    FROM (

/* (SELECT U1.EMAIL, S1.GRNNUM 
     FROM RDT_USER U1, 
      (SELECT O.ID, GRNNUM 
       FROM RDT_ORGANIZATION O, 
        (SELECT GRNNUM, RECEPIENTCODE, ORGINATORCODE 
         FROM RDT_GOODSRECEIPTNOTE M 
         WHERE M.ACTIONSTATUS = 0 
         AND M.LATEST = 1 
         AND (SYSDATE - M.GENDATE) >= 0) S 
       WHERE O.FUCODE = S.ORGINATORCODE) S1 

     WHERE U1.ORGID = S1.ID)*/ A///////here am getting right paranthesis missing, 

    (SELECT U.EMAIL, T1.GRNNUM 
     FROM RDT_USER U, 
      (SELECT O.ID, GRNNUM 
       FROM RDT_ORGANIZATION O, 
        (SELECT GRNNUM, RECEPIENTCODE, ORGINATORCODE 
         FROM RDT_GOODSRECEIPTNOTE M 
         WHERE M.ACTIONSTATUS = 0 
         AND M.LATEST = 1 
         AND (SYSDATE - M.GENDATE) >= 0) T 
       WHERE O.FUCODE = T.ORGINATORCODE) T1 

     WHERE U.ORGID = T1.ID) B) 
WHERE A.GRNNUM = B.GRNNUM 
+1

你需要一個逗號(',')在'A'之後,你在那裏缺少palenthesis。 –

+0

評論部分實際上被忽略。如果你只是從查詢中刪除它,你會得到同樣的錯誤。你想用'A /////// ...'部分達到什麼目的?記住SQL中的註釋以'--'開頭。另外,弗洛林評論說,如果''''在'select'子句中,則需要用逗號將它與第二個'select'分開。 –

+0

這是沒有評論部分來解釋你我喜歡那.......... – sunleo

回答

1

這兩個子查詢/直列意見需要以某種方式連接。你可能需要一個交叉連接 - 通過它們之間的逗號表示 - 在這種情況下,您也可以刪除一組括號:

SELECT * 
FROM (SELECT U1.EMAIL, S1.GRNNUM 
     FROM RDT_USER U1, 
       (SELECT O.ID, GRNNUM 
       FROM RDT_ORGANIZATION O, 
         (SELECT GRNNUM, RECEPIENTCODE, ORGINATORCODE 
         FROM RDT_GOODSRECEIPTNOTE M 
         WHERE M.ACTIONSTATUS = 0 
         AND M.LATEST = 1 
         AND (SYSDATE - M.GENDATE) >= 0) S 
       WHERE O.FUCODE = S.ORGINATORCODE) S1 

     WHERE U1.ORGID = S1.ID) A, 

     (SELECT U.EMAIL, T1.GRNNUM 
     FROM RDT_USER U, 
       (SELECT O.ID, GRNNUM 
       FROM RDT_ORGANIZATION O, 
         (SELECT GRNNUM, RECEPIENTCODE, ORGINATORCODE 
         FROM RDT_GOODSRECEIPTNOTE M 
         WHERE M.ACTIONSTATUS = 0 
         AND M.LATEST = 1 
         AND (SYSDATE - M.GENDATE) >= 0) T 
       WHERE O.FUCODE = T.ORGINATORCODE) T1 
     WHERE U.ORGID = T1.ID) B 
WHERE A.GRNNUM = B.GRNNUM; 

編輯我看看你的查詢越多,我看到的問題越多。

  1. 您的內聯視圖/子查詢是相同的。交叉連接的唯一影響是增加執行時間。
  2. 你爲什麼要交叉連接?內部連接就足夠了。
  3. 您的內部查詢缺少某些列規格,您在外部查詢中引用了該規範,以便進行連接。這不起作用。

您的查詢的核心基本上是這樣的邏輯:

select grnnum, 
     recepientcode, 
     originatorcode 
from rdt_goodsreceiptnote 
where actionstatus  = 0 
and latest    = 1 
and sysdate - gendate >= 0; 

你那麼十字rdt_organization加入這個,然後加入交叉與rdt_user;這個混亂然後與自己交叉,出於某種原因。這可以大大內簡化連接:

select rdt_user.email, 
     rdt_goodsreceiptnote.grnnum 

from rdt_goodsreceiptnote 

join rdt_organization 
on  rdt_organization.fucode = rdt_goodsreceiptnode.originatorcode 

join rdt_user 
on  rdt_user.orgid = rdt_organization.id 

where rdt_goodsreceiptnode.actionstatus  = 0 
and rdt_goodsreceiptnode.latest    = 1 
and sysdate - rdt_goodsreceiptnode.gendate >= 0; 

沒有理由爲你做這兩次,交叉聯接,所以這是它。很容易,是吧?

1

你需要把別名A到評論如下:

SELECT * 
    FROM (

/* (SELECT U1.EMAIL, S1.GRNNUM 
     FROM RDT_USER U1, 
      (SELECT O.ID, GRNNUM 
       FROM RDT_ORGANIZATION O, 
        (SELECT GRNNUM, RECEPIENTCODE, ORGINATORCODE 
         FROM RDT_GOODSRECEIPTNOTE M 
         WHERE M.ACTIONSTATUS = 0 
         AND M.LATEST = 1 
         AND (SYSDATE - M.GENDATE) >= 0) S 
       WHERE O.FUCODE = S.ORGINATORCODE) S1 

     WHERE U1.ORGID = S1.ID) A///////here am getting right paranthesis missing, 
*/ 
    (SELECT U.EMAIL, T1.GRNNUM 
     FROM RDT_USER U, 
      (SELECT O.ID, GRNNUM 
       FROM RDT_ORGANIZATION O, 
        (SELECT GRNNUM, RECEPIENTCODE, ORGINATORCODE 
         FROM RDT_GOODSRECEIPTNOTE M 
         WHERE M.ACTIONSTATUS = 0 
         AND M.LATEST = 1 
         AND (SYSDATE - M.GENDATE) >= 0) T 
       WHERE O.FUCODE = T.ORGINATORCODE) T1 

     WHERE U.ORGID = T1.ID) B) 
WHERE A.GRNNUM = B.GRNNUM