0

我正在处理一个 sql 文件,试图制作一个脚本,该脚本可以带回显示的表中的所有数据或表中的所有数据加上 3 个月的数据。我不断收到一条错误消息, error 00905 missing keyword但我不明白为什么。

我查看了语法,这一切对我来说都是正确的。我会在它说发生错误的地方放置一个标记(在第一个内部连接处)。我更改了所有表名以使其看起来更好,因为它超出了语法。

任何帮助都会非常感谢。这只是代码的一部分,但我确信它必须在这里。

WHEN Table_typ_cde = '1' -- Pulling all data --
  THEN
    INNER JOIN  Table   acp ON Table_oid = Table_oid
    INNER JOIN  Table   loss ON Table_oid = Table_oid
    LEFT OUTER JOIN Table veh ON Table_oid = Table_oid and Table_nbr=1
    INNER JOIN Table   brnch ON Table_OID = Table_oid
    INNER JOIN Table   a ON Table_OID = Table_oid
    INNER JOIN Table   c Table_OID = Table_oid
    INNER JOIN Table   s ON Table_OID = Table_oid
    INNER JOIN Table   r ON Table_OID = Table_oid
    INNER JOIN Table   grp ON Table_oid = Table_oid
    INNER JOIN Table on Table_id = Table_id
    WHERE Table_ID <> 2
 WHEN Table_cde = '2' -- Pulling all data within the last 3 months along with all present data --
 THEN
    INNER JOIN  Table   acp ON Table_oid = Table_oid
    INNER JOIN  Table   loss ON Table_oid = Table_oid
    LEFT OUTER JOIN Table veh ON Table_oid = Table_oid and Table_nbr=1
    INNER JOIN Table   brnch ON Table_OID = Table_oid
    INNER JOIN Table   a ON Table_OID = Table_oid
    INNER JOIN Table   c ON Table_OID = Table_oid
    INNER JOIN Table   s ON Table_OID = Table_oid
    INNER JOIN Table   r ON Table_OID = Table_oid
    INNER JOIN Table   grp ON Table_oid = Table_oid
    INNER JOIN Table on Table_id = Table_id
    WHERE Table_ID <> 2
    AND df.DATE_CREATED BETWEEN ADD_MONTHS(SYSDATE, -6)
    AND sysdate
END                                         
) core
4

2 回答 2

1

你不能破坏JOINusing CASE。我在您的查询的某些部分中看到了这一点,

THEN
   INNER JOIN  Table   acp ON Table_oid = Table_oid
   INNER JOIN  Table   loss ON Table_oid = Table_oid

这是错误的,您必须在INNER JOIN关键字之前提供表名。

于 2012-10-05T03:14:06.490 回答
0

您有两组看似相等的连接。然后你有一个你希望有条件地应用的日期过滤器。您需要在 WHERE 子句而不是 FROM 中应用它。有些像这样

FROM  ... INNER JOIN  Table   acp ON Table_oid = Table_oid
    INNER JOIN  Table   loss ON Table_oid = Table_oid
    LEFT OUTER JOIN Table veh ON Table_oid = Table_oid and Table_nbr=1
    INNER JOIN Table   brnch ON Table_OID = Table_oid
    INNER JOIN Table   a ON Table_OID = Table_oid
    INNER JOIN Table   c ON Table_OID = Table_oid
    INNER JOIN Table   s ON Table_OID = Table_oid
    INNER JOIN Table   r ON Table_OID = Table_oid
    INNER JOIN Table   grp ON Table_oid = Table_oid
    INNER JOIN Table on Table_id = Table_id
WHERE Table_ID <> 2
    AND (Table_cde = '1' 
          or ( Table_cde = '2' 
          and df.DATE_CREATED BETWEEN ADD_MONTHS(SYSDATE, -6) AND sysdate ))
于 2012-10-05T07:38:25.893 回答