-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///////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
4

2 回答 2

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
于 2013-01-21T09:59:20.313 回答
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;

在交叉连接中,你没有理由这样做两次,就是这样。容易多了,是吗?

于 2013-01-21T10:01:58.117 回答