select a.mcd,b.mnm,a.gdcst,a.gdcst1,a.gdhcst,a.rkbn,a.gdretcls,
      to_char(a.gdstp,'yyyy/mm/dd hh24:mi') gdstp
  from afm04 b,afm02e a
  where a.ijan=:ijan
    and a.mcd=b.mcd(+)
  order by decode(a.rkbn,'0',0,1),a.mcd