无效的sql语句错误

时间:2016-01-02 13:05:46

标签: sql oracle

我正在使用以下查询缩写子查询,但我收到错误

  

无效的sql语句错误

我不知道这里有什么问题

select enq.followup_sr_no ColFolSrno,case when enq.followup_sr_no=(select max(followup_sr_no) from  xxcus.XXACL_PN_ENQUIRY_FOLLOWUP where cef_mkey=enq.cef_mkey) and enq.activity_id not in (80,40) then 'Edit' else 'View' end ColViewEdit,

ENQ.FOLLOWUP_TYPE_ID ColFolTypeId,FOL.FOLLOW_TYPE ColFolType,ENQ.PRIORITY_ID ColPrioId,PRI.PRIORITY ColPriority,
to_char(ENQ.FOLLOWUP_DATE,'dd/MM/yyyy') ColFolUpDt,ENQ.ACTIVITY_ID ColActId,ACT.ACTIVITY ColActivity,ENQ.REMARKS ColComments,

'Flat-' || (select FP.FLAT_NO FROM xxcus.xxacl_pn_ratecard rc, xxcus.xxacl_pn_flatproj_v fp where RC.FLAT_ID=FP.FLAT_ID and RC.CEF_MKEY=enq.CEF_MKEY and RC.FOLLOWUP_SR_NO=enq.FOLLOWUP_SR_NO )  ColPrint, 

to_char(ENQ.NEXT_FOLLOW_UP_DATE,'dd/MM/yyyy') ColNxtFolUpDt,ENQ.NEXT_ACTIVITY_ID ColNxtActId,NACT.ACTIVITY ColNxtActivity, (select RC.FLAT_ID FROM xxcus.xxacl_pn_ratecard rc where RC.CEF_MKEY=enq.CEF_MKEY and RC.FOLLOWUP_SR_NO=enq.FOLLOWUP_SR_NO)FLAT_ID ,

enq.mkey  mkey , enq.ATTENDED_BY_MKEY AttendedByMkey , em.user_id User_Id , em.login_name EnqueryBy

from XXACL_PN_EMPLOYEE_ALL_V em, xxcus.XXACL_PN_ENQUIRY_FOLLOWUP enq, xxcus.XXACL_PN_FOLLOWUP_TYPE_V fol,xxcus.XXACL_PN_PRIORITY_V pri,xxcus.XXACL_PN_ACTIVITY_V act,xxcus.XXACL_PN_ACTIVITY_V nact, xxcus.xxacl_pn_flatproj_v flt 

where  ENQ.FOLLOWUP_TYPE_ID = FOL.FOLLOW_TYPE_ID(+) and ENQ.PRIORITY_ID = PRI.PRIORITY_ID(+) and ENQ.ACTIVITY_ID = ACT.ACTIVITY_ID(+) and ENQ.NEXT_ACTIVITY_ID = NACT.ACTIVITY_ID(+) AND enq.flat_id = flt.flat_id(+) and enq.ATTENDED_BY_MKEY = em.USER_ID(+) and  and cef_mkey=2590  order by enq.followup_sr_no desc

2 个答案:

答案 0 :(得分:1)

最后一行有两个ANDand and cef_mkey=2590。删除一个,这是无效的语法。

select enq.followup_sr_no ColFolSrno,case when enq.followup_sr_no=(select max(followup_sr_no) from  xxcus.XXACL_PN_ENQUIRY_FOLLOWUP where cef_mkey=enq.cef_mkey) and enq.activity_id not in (80,40) then 'Edit' else 'View' end ColViewEdit,
ENQ.FOLLOWUP_TYPE_ID ColFolTypeId,FOL.FOLLOW_TYPE ColFolType,ENQ.PRIORITY_ID ColPrioId,PRI.PRIORITY ColPriority,
to_char(ENQ.FOLLOWUP_DATE,'dd/MM/yyyy') ColFolUpDt,ENQ.ACTIVITY_ID ColActId,ACT.ACTIVITY ColActivity,ENQ.REMARKS ColComments,
'Flat-' || (select FP.FLAT_NO FROM xxcus.xxacl_pn_ratecard rc, xxcus.xxacl_pn_flatproj_v fp where RC.FLAT_ID=FP.FLAT_ID and RC.CEF_MKEY=enq.CEF_MKEY and RC.FOLLOWUP_SR_NO=enq.FOLLOWUP_SR_NO )  ColPrint, 
to_char(ENQ.NEXT_FOLLOW_UP_DATE,'dd/MM/yyyy') ColNxtFolUpDt,ENQ.NEXT_ACTIVITY_ID ColNxtActId,NACT.ACTIVITY ColNxtActivity, (select RC.FLAT_ID FROM xxcus.xxacl_pn_ratecard rc where RC.CEF_MKEY=enq.CEF_MKEY and RC.FOLLOWUP_SR_NO=enq.FOLLOWUP_SR_NO)FLAT_ID ,
enq.mkey  mkey , enq.ATTENDED_BY_MKEY AttendedByMkey , em.user_id User_Id , em.login_name EnqueryBy
from XXACL_PN_EMPLOYEE_ALL_V em, xxcus.XXACL_PN_ENQUIRY_FOLLOWUP enq, xxcus.XXACL_PN_FOLLOWUP_TYPE_V fol,xxcus.XXACL_PN_PRIORITY_V pri,xxcus.XXACL_PN_ACTIVITY_V act,xxcus.XXACL_PN_ACTIVITY_V nact, xxcus.xxacl_pn_flatproj_v flt 
where  ENQ.FOLLOWUP_TYPE_ID = FOL.FOLLOW_TYPE_ID(+) and ENQ.PRIORITY_ID = PRI.PRIORITY_ID(+) and ENQ.ACTIVITY_ID = ACT.ACTIVITY_ID(+) and ENQ.NEXT_ACTIVITY_ID = NACT.ACTIVITY_ID(+) AND enq.flat_id = flt.flat_id(+) and enq.ATTENDED_BY_MKEY = em.USER_ID(+) and  cef_mkey=2590  order by enq.followup_sr_no desc

答案 1 :(得分:0)

在最后一行查询中

where  ENQ.FOLLOWUP_TYPE_ID = FOL.FOLLOW_TYPE_ID(+) and ENQ.PRIORITY_ID = PRI.PRIORITY_ID(+) and ENQ.ACTIVITY_ID = ACT.ACTIVITY_ID(+) and ENQ.NEXT_ACTIVITY_ID = NACT.ACTIVITY_ID(+) AND enq.flat_id = flt.flat_id(+) and enq.ATTENDED_BY_MKEY = em.USER_ID(+) and  and cef_mkey=2590  order by enq.followup_sr_no desc

请注意,您连续两次使用AND运算符。

where  ENQ.FOLLOWUP_TYPE_ID = FOL.FOLLOW_TYPE_ID(+) and ENQ.PRIORITY_ID = PRI.PRIORITY_ID(+) and ENQ.ACTIVITY_ID = ACT.ACTIVITY_ID(+) and ENQ.NEXT_ACTIVITY_ID = NACT.ACTIVITY_ID(+) AND enq.flat_id = flt.flat_id(+) and enq.ATTENDED_BY_MKEY = em.USER_ID(+) and cef_mkey=2590  order by enq.followup_sr_no desc

这就是这条线应该是什么。

此外,如果您使用ANSI-92而不是ANSI-89语法(JOIN而不是FROM语句中的所有表),您可能不会收到此错误,因为您在WHERE子句中只有一个条件。