简体   繁体   中英

Left Outer Join Error

I get this error for the below query when I am trying to make a left outer join

ERROR at line 7: ORA-00936: missing expression

select s.FINAL_BSAL,s.EMP_No,p.ERN_DDCT_CATNO,p.AMOUNT,n.NO_PAY_AMOUNT,
p.Pay_month,a.ARREARS_AMOUNT from salary_details s,pay_details p,Arrears a,No_Pay n 
where s.emp_no=p.emp_no 
and 
s.SAL_NO  IN (SELECT MAX(SAL_NO) FROM SALARY_DETAILS group by EMP_NO) 
AND
to_char(P.PAY_MONTH,'MM-YYYY') =to_char(n.NO_PAY_MONTH,'MM-YYYY') (+)
AND
to_char(P.PAY_MONTH,'MM-YYYY')=to_char(a.ARREARS_MONTH,'MM-YYYY') ;

Please help.

The issue lies with the placement of (+) :

Instead of:

to_char(P.PAY_MONTH,'MM-YYYY') =to_char(n.NO_PAY_MONTH,'MM-YYYY') (+)

you should do:

to_char(P.PAY_MONTH,'MM-YYYY') =to_char(n.NO_PAY_MONTH (+),'MM-YYYY')

However, if I were you, I'd go with @Walter_Ritzel's approach and use ANSI JOIN syntax instead. That and properly format the SQL so that it's readable...

Try this:

select s.FINAL_BSAL
  ,s.EMP_No
  ,p.ERN_DDCT_CATNO
  ,p.AMOUNT
  ,n.NO_PAY_AMOUNT
  ,p.Pay_month
  ,a.ARREARS_AMOUNT
from salary_details s inner join pay_details p on s.emp_no = p.emp_no
inner join Arrears a on to_char(P.PAY_MONTH,'MM-YYYY')= to_char(a.ARREARS_MONTH,'MM-YYYY')
left outer join No_Pay n on to_char(P.PAY_MONTH,'MM-YYYY') = to_char(n.NO_PAY_MONTH,'MM-YYYY') 
where s.SAL_NO IN (SELECT MAX(SAL_NO) FROM SALARY_DETAILS group by EMP_NO);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM