2014-09-04 132 views
0

我在PostgreSQL中编写了一个查询,该查询完美地工作,但在Oracle SQL中执行时不起作用。我竭尽全力想出问题所在。请帮我修复它。oci_execute():ORA-00907:缺少右括号

SELECT tb1.executive_code,tb1.month,tb1.year,tb1.count_req_no, 
    t1.count_enquiry_closed,tb1.sum_exp_amt,tb1.sum_trr_exp_tenure, 
    tb1.sum_exp_tenure,t1.avg_total_case_tat,tb1.count_finance_amt, 
    tb1.count_mls,t1.count_rejection_negative,t1.count_dedupe_date, 
    t1.count_rejection_pre,t1.count_fi_feedback_date, 
    t1.count_rejection_fi,t1.count_ready_date 
FROM (
    SELECT dealing_executive_code AS executive_code, 
    date_part('month',tb.req_date) AS month, 
    date_part('year',tb.req_date) AS year, 
    count(tb.req_no) AS count_req_no, 
    dealing_executive_code,sum(tb.exp_amt) AS sum_exp_amt, 
    sum(tb.tent_net_irr_cost_all_payout*tb.exp_amt*tb.tenure) AS sum_trr_exp_tenure, 
    sum(tb.exp_amt*tb.tenure) AS sum_exp_tenure, 
    count(case when insurance_finance_amt !='0' then '1' end) AS count_finance_amt, 
    count(case when mls_finance_amount !='0' then '1' end) AS count_mls 
    FROM tb_requisition_report AS tb 
    GROUP BY date_part('month',tb.req_date),date_part('year',tb.req_date), 
    tb.dealing_executive_code 
) AS tb1 
LEFT JOIN (
    SELECT date_part('month',enq_date) AS d1, 
    date_part('year',enq_date) AS d2, 
    count(case when enquiry_status='CLOSED' then '1' end)AS count_enquiry_closed, 
    dealing_executive_code,avg(total_case_tat) AS avg_total_case_tat, 
    count(case when lost_rejection_stage='NEGATIVE DEDUPE STAGE' then '1' end) AS count_rejection_negative, 
    count(case when dedupe_date IS NOT NULL then '1' end) AS count_dedupe_date, 
    count(case when lost_rejection_stage='PRE SANCTION DOCUMENT PENDIN' then '1' end) AS count_rejection_pre, 
    count(case when fi_feedback_date IS NOT NULL then '1' end) AS count_fi_feedback_date, 
    count(case when lost_rejection_stage='FI NEGATIVE CLEARANCE STAGE' then '1' end) AS count_rejection_fi, 
    count(case when fi_ready_date IS NOT NULL then '1' end) AS count_ready_date 
    FROM tb_lead_tracker 
    GROUP BY date_part('month',enq_date),date_part('year',enq_date), 
    dealing_executive_code 
) AS t1 
ON t1.dealing_executive_code=tb1.dealing_executive_code 
AND t1.d1=tb1.month AND t1.d2=tb1.year 
+0

我已经修复了诸如date_part之类的问题,但是仍然无法找出问题的原因 – Praneeth 2014-09-04 06:12:20

+0

还有很多语法问题--eft join语法不正确,您不需要“as”来给表格添加别名。通过运行单个查询开始,您将找到它 – Sathya 2014-09-04 06:18:54

+1

向我们展示您将查询转换为Oracle的尝试 - 当Oracle中没有'date_part'函数时,将所有'date_part'调用留在所有'date_part'函数中(除非您已创建一个)并不能帮助我们弄清楚你知道哪些语法错误,哪些是你不知道的。如果你在SQL * Plus中运行查询,那会给你错误的行和列(不知道你正在使用的任何框架是否也给了你这个能力)。 – 2014-09-04 06:21:30

回答

1

不能在表中使用AS作为Oracle中的表别名,只能用于列别名。因此,例如,本:

FROM tb_requisition_report AS tb 

...必须是:

FROM tb_requisition_report tb 

与同为其他内嵌了意见。目前,AS被解析器看作是一个不长的地方,它回到了ORA-00907,就像它经常这样做 - 通常并不意味着实际上有一个不平衡的括号,只是没有找到它的预期位置,这通常是因为另一个语法错误。解析器无法解释你的意思,因此不能总是更具体地说明什么是错误的,特别是当涉及其他关键字时。

Sathya已经提到,在评论中,以及datepart不是内置的Oracle函数,因此可能无法解决所有问题。