SQL从关键字不在预期的位置?

时间:2016-08-13 11:25:25

标签: sql oracle cognos

我在Oracle中使用SQL。我已经使用别名多次拉回同一个表格(但代码似乎没有读得那么多)。

我收到了消息

  

在预期的地方找不到ORA-00923 FROM关键字。

为什么我在下面的代码中收到此消息的任何想法?

select 
T1."MORTGAGE" "c1", 
T1."ACCNO" "c2", 
T2."TIERRATE" "c3", 
T3."PRODCODE" "c4"
T3."MTRANEFF" "c5", 
T3."RECTYPE" "c6",
T4. "PRODCODE" "c7",
T4."MTRANEFF" "c8", 
T5."TIERRATE" "c9"
from 
"BEL"."ACM01" T1,           
"BEL"."ACM03" T2,       
"BEL"."ACT13" T3,       
"BEL"."ACT13" T4,       
"BEL"."ACM03" T5        
where 
T1."PRODCODE"=T2."PRODCODE" and 
T1."ACCNO"=T3."ACCNO" and 
T3."ACCNO"=T4."ACCNO" AND 
T1."PRODCODE"=T5."PRODCODE" and 
T3."RECTYPE"='PR' and T1."PRODCODE" in ('NOR', 'UF3')

1 个答案:

答案 0 :(得分:2)

你在第四行" c4"之后错过了一个逗号。

但是,您应该学会使用正确的,明确的JOIN语法。查询应如下所示:

select T1."MORTGAGE" as "c1",  T1."ACCNO" as "c2",  T2."TIERRATE" as "c3", 
       T3."PRODCODE" as "c4", T3."MTRANEFF" as "c5", T3."RECTYPE" as "c6",
       T4. "PRODCODE" as "c7", T4."MTRANEFF" as "c8",  T5."TIERRATE" as "c9"
from "BEL"."ACM01" T1 join          
     "BEL"."ACM03" T2
     on T1."PRODCODE" = T2."PRODCODE" join
     "BEL"."ACT13" T3
     on T1."ACCNO" = T3."ACCNO" join
     "BEL"."ACT13" T4
     on T3."ACCNO" = T4."ACCNO" join    
     "BEL"."ACM03" T5        
     on T1."PRODCODE" = T5."PRODCODE" 
where T3."RECTYPE" = 'PR' and T1."PRODCODE" in ('NOR', 'UF3');

注意:

  • 从不FROM子句中使用逗号。 始终使用正确的显式JOIN语法。
  • 使用as定义列别名。这个习惯有助于在遗漏逗号时发现错误。
  • 不要在双引号之间添加列名。它只会使查询更难阅读。选择不需要转义的列名称。
  • 为您提供有意义的表别名。只需枚举T1T2等,就无法向阅读查询的人提供更多信息。