0

I have the following query which is giving error ORA-00905: missing keyword. I've not been able to find the syntax despite continuous efforts for last few hours. Please help.

SELECT a.DOCUMENT_CATEGORY,
         a.template_id,
         a.category_id,
         a.REVIEW_CATEGORY,
         a.WITH_BIDS,
         a.WITH_FINAL_DOCUMENTS,
         b.divn_id,
         b.deptt_id,
         a.vdr_id,
         C.DEPARTMENT,
         a.TEMPLATE_TITLE
    FROM DCTM_VDR_REF_DTLS a, DCTM_VDR_REF_MASTER b, VW_DIVN_DIR c
   WHERE     b.DIVN_ID = c.DIVN_CODE
         AND b.DEPTT_ID = c.SECTN_CODE
         AND a.vdr_id = b.vdr_id
         AND (b.REFERENCE_NUMBER, b.APPROVED_ON) IN
                (  SELECT MAX (REFERENCE_NUMBER), MAX (APPROVED_ON)
                     FROM DCTM_VDR_REF_MASTER
                    WHERE     REFERENCE_NUMBER =
                                 (SELECT DISTINCT
                                         NVL (TRIM (MR_NUMBER), TRIM (TENDER_NO))
                                    FROM EILEDMS.EIL_DOCUMENT_SV@EDMS_DBLINK
                                   WHERE     object_name =
                                                'A307-0IC-JA-MR-7960-1030-157-FOA'
                                         AND r_object_type =
                                                'eil_foa_order_pr_doc'
                                         AND (   title = 'FOA'
                                              OR title = 'DRAFT FOA'))
                          AND APPROVED_ON IS NOT NULL
                 GROUP BY DIVN_ID, DEPTT_ID)
         AND REVIEW_CATEGORY <> 'Delete Category'
         AND (CASE (SELECT IS_SCHEDULE_LOCKED
                      FROM DCTM_VENDOR_SCHEDULE
                     WHERE SCH_ID = 359)
                 WHEN 0
                 THEN
                    1
                 WHEN 1
                 THEN
                    (a.template_id || '-' || a.category_id) IN
                       (SELECT template_id || '-' || category_id
                          FROM DCTM_VENDOR_SCH_UNLOCK_DTLS
                         WHERE     APPROVAL = 'Y'
                               AND APPROVAL_UPTO >= SYSDATE
                               AND CONSUMED = 0
                               AND sch_ID = 359)
              END) = 1
ORDER BY c.DEPARTMENT ASC,
         a.TEMPLATE_ID,
         a.SORT_ORDER,
         a.DOCUMENT_CATEGORY ASC

Can't we use IN clause inside a THEN statement?

4

2 回答 2

2

现在您已经编辑了您的问题,看起来您只是想在 DCTM_VENDOR_SCH_UNLOCK_DTLS 中查找 category_id 和 template_id。以下内容对您有用吗?

then 
(
  SELECT COUNT(*) -- 1 if found, 0 otherwise
    FROM DCTM_VENDOR_SCH_UNLOCK_DTLS
   WHERE     APPROVAL = 'Y'
         AND APPROVAL_UPTO >= SYSDATE
         AND CONSUMED = 0
         AND sch_ID = 359
         AND template_id = a.template_id
         AND category_id = a.category_id
         AND rownum = 1
)
于 2013-11-08T11:13:19.717 回答
0

这实际上与 WHERE 是否允许之后的 IN 子句无关。表达方式

a.category_id IN (SELECT ...)

评估为 TRUE 或 FALSE。你的陈述

a.template_id || '-' || a.category_id IN (SELECT ...)

尝试将 TRUE 或 FALSE 与 a.template_id 和减号连接起来。这是不可能的,因为 Oracle SQL 中没有布尔类型。考虑一下您实际想要连接的内容。

编辑:现在您设置了括号,您将一个字符串与另一个由 select 语句产生的字符串进行比较。到目前为止还好。但仍然:所有这些都计算为布尔值,而不是数字。然后你的第一个结果是一个数字(1),你的第二个是一个布尔值(TRUE 或 FALSE)。Oracle SQL 没有布尔类型,因此您的表达式对解析器没有意义,并且会出现语法错误。

于 2013-11-08T10:03:58.153 回答