0

请查找以下查询。当我运行这个查询时,我得到一个 ORA-00907:缺少右括号错误。我无法理解此查询的问题。请给我这个错误的解决方案。我已阅读有关此主题的一些相关主题。但是,我没有得到正确的解决方案。我使用的是 Oracle 10g 版本。

查询:

SELECT A.City||'.' AS AAddress,
    M_InOut_Header_v.Org_Location_ID AS Org_Location_ID, 
    M_InOut_Header_v.ContactName, 
    M_InOut_Header_v.Title, 
    M_InOut_Header_v.EMail, 
    M_InOut_Header_v.Phone, 
    M_InOut_Header_v.BPGreeting, 
    M_InOut_Header_v.Name2, 
    M_InOut_Header_v.Name, 
    B.City||'.' AS BAddress, 
    M_InOut_Header_v.C_Location_ID AS C_Location_ID, 
    M_InOut_Header_v.BPContactGreeting,
    --M_InOut_Header_v.BPGreeting,
    --M_InOut_Header_v.Name,
    --M_InOut_Header_v.Name2, 
    M_InOut_Header_v.Address1, 
    M_InOut_Header_v.Address2, 
    M_InOut_Header_v.Address3, 
    M_InOut_Header_v.Address4, 
    M_InOut_Header_v.City, 
    M_InOut_Header_v.POSTAL1, 
    M_InOut_Header_v.CountryName, 
    --M_InOut_Header_v.BPContactGreeting, 
    --M_InOut_Header_v.Name, 
    M_InOut_Header_v.OrderRemarks, 
    (SELECT NVL(C_Order.DocumentNo,'')||'
      - '||NVL(TRIM(TO_CHAR(C_Order.DateOrdered,'DD/MM/YYYY')),'') 
        FROM C_Order 
        WHERE M_InOut_Header_v.C_Order_ID=C_Order.C_Order_ID
    ) AS CC_Order_ID, 
    M_InOut_Header_v.C_Order_ID AS C_Order_ID, 
    M_InOut_Header_v.OrderType, 
    M_InOut_Header_v.ReferenceNo, 
    M_InOut_Header_v.POReference, 
    (SELECT NVL(M_Warehouse.Name,'') 
        FROM M_Warehouse 
        WHERE M_InOut_Header_v.M_Warehouse_ID=M_Warehouse.M_Warehouse_ID
    ) AS DM_Warehouse_ID, 
    M_InOut_Header_v.M_Warehouse_ID AS M_Warehouse_ID, 
    (SELECT NVL(M_Shipper.Name,'') 
        FROM M_Shipper 
        WHERE M_InOut_Header_v.M_Shipper_ID=M_Shipper.M_Shipper_ID
    ) AS EM_Shipper_ID, 
    M_InOut_Header_v.M_Shipper_ID AS M_Shipper_ID, 
    M_InOut_Header_v.Vehicle_No_BizInt, 
    M_InOut_Header_v.TrackingNo, 
    M_InOut_Header_v.Permit_No_BizInt, 
    M_InOut_Header_v.LR_Number_BizInt, 
    M_InOut_Header_v.FREIGHTCOSTRULE2, 
    M_InOut_Header_v.FreightAmt, 
    M_InOut_Header_v.POREMARKS, 
    M_InOut_Header_v.NoPackages,
    M_InOut_Header_v.Gross_Weight_BizInt, 
    M_InOut_Header_v.UOMSymbol, 
    M_InOut_Header_v.SalesRepPhone, 
    M_InOut_Header_v.SalesRepEmail, 
    M_InOut_Header_v.DocumentType, 
    InOut_Header_v.DocumentNo, 
    M_InOut_Header_v.MovementDate, 
    M_InOut_Header_v.Description, 
    (SELECT NVL(M_InOut.DocumentNo,'')||'
      - '||NVL(TRIM(TO_CHAR(M_InOut.MovementDate,'DD/MM/YYYY')),'') 
        FROM M_InOut 
        WHERE M_InOut_Header_v.M_InOut_ID=M_InOut.M_InOut_ID
    ) AS FM_InOut_ID, 
    M_InOut_Header_v.M_InOut_ID AS M_InOut_ID, 
    M_InOut_Header_v.DocumentTypeNote, 
    M_InOut_Header_v.REMARKS1, 
    M_InOut_Header_v.REMARKS2, 
    M_InOut_Header_v.REMARKS3, 
    M_InOut_Header_v.REMARKS4 
FROM M_InOut_Header_v 
LEFT OUTER JOIN C_Location A 
ON (M_InOut_Header_v.Org_Location_ID=A.C_Location_ID) 
LEFT OUTER JOIN C_Location B 
ON (M_InOut_Header_v.C_Location_ID=B.C_Location_ID) 
WHERE (M_InOut_Header_v.M_InOut_ID=1002241) 
    AND M_InOut_Header_v.AD_Client_ID IN (1000008,0) 
    AND M_InOut_Header_v.AD_Org_ID IN (1000099,1000098,0,1000100,1000096,1000097) 
    AND (A.C_Location_ID IS NULL 
            OR A.C_Location_ID NOT IN ( 
                SELECT PA.Record_ID FROM AD_Private_Access AS PA 
                WHERE PA.AD_Table_ID = 162 AND PA.AD_User_ID <> 1013144 
                AND PA.IsActive = 'Y' 
            )) 
    AND ( B.C_Location_ID IS NULL 
            OR B.C_Location_ID NOT IN ( 
                SELECT ADP.Record_ID FROM AD_Private_Access AS ADP 
                WHERE ADP.AD_Table_ID = 162 AND ADP.AD_User_ID <> 1013144 
                AND ADP.IsActive = 'Y' 
            ))
ORDER BY M_InOut_Header_v.DocumentNo;

这给了我:

ORA-00907: missing right parenthesis
00907. 00000 -  "missing right parenthesis"
*Cause:    
*Action:
Error at Line: 80 Column: 26

但我没有发现那一行有任何错误。我认为它在语法上是正确的。

4

1 回答 1

5

行号有点误导,但它指向问题的开始。问题在于这两个子查询:

                    SELECT PA.Record_ID FROM AD_Private_Access AS PA 
                    WHERE PA.AD_Table_ID = 162 AND PA.AD_User_ID <> 1013144 
                    AND PA.IsActive = 'Y' 

和:

                    SELECT ADP.Record_ID FROM AD_Private_Access AS ADP 
                    WHERE ADP.AD_Table_ID = 162 AND ADP.AD_User_ID <> 1013144 
                    AND ADP.IsActive = 'Y' 

您不能使用AS来标记表名的别名,只能(可选地)用于列名或表达式。实际上没有缺少括号。很难确切知道解析器在想什么,但在这种情况下,它看起来像是试图将 解释AS PA为该子查询的列别名,这意味着子查询现在应该已经结束,所以应该有一个右括号已经。(另一种选择可能是尝试将AS 其视为表 alias,但随后必须尝试确定其PA含义; plusAS是一个关键字,因此无论如何它都不能作为别名有效)。

只需从这两个中删除AS关键字,它就会起作用(或转到另一个错误)。

                    SELECT PA.Record_ID FROM AD_Private_Access PA 
                    ...

和:

                    SELECT ADP.Record_ID FROM AD_Private_Access ADP 
                    ...
于 2013-08-22T10:50:41.470 回答