select    a.wseq,a.ktktcd,a.cucd,b.cunm,a.cuscd,c.spnm,a.vseq,a.mcd,m04.mnm,
          a.gdflg,to_char(a.dat1,'yyyy/mm/dd') dat1,to_char(a.climit,'yyyy/mm/dd') climit,
          a.dcubcd,a.cuslip2,a.bbno,a.com1,
          a.dtxt1,a.dtxt2,a.ltxt1,a.ltxt2,
          a.iseq,a.iseq80,a.vlin,a.jan,a.ijan,a.gdjnm,a.gdjstnd,
          a.gdcnum,a.gdbnum,a.gdstun gdhtun,a.gdcls9,f.scls5 gdcls9nm,
          a.mvpno,a.cst,a.gdcst,a.com,a.pgvseq,
          round(nvl(a.mvpno,0)*nvl(a.gdcst,0)) sgdcst,
          calc_amt(a.cucd,a.mvpno,a.cst) scst,
          d.chgnm chgnm,
          to_char(a.idat,'yyyy/mm/dd hh24:mi:ss') idat,
          e.chgnm upchgnm,
          case when a.udat=a.idat then null else to_char(a.udat,'yyyy/mm/dd hh24:mi:ss') end udat,
          m02.undkbn
     from afm02 m02, afm04 m04, afm90 f,afm08 e,afm08 d,afm032 c,afm03 b,afw80 a
     where a.wseq=:wseq and a.cls='1'
          and ((:cucd is null and :cuscd is null) or (a.cucd=:cucd and a.cuscd=:cuscd))
          and nvl(a.dflg,0)<>1
          and a.cucd=b.cucd(+)
          and a.cucd=c.cucd(+) and a.cuscd=c.cuscd(+)
          and a.chgcd=d.chgcd(+)
          and a.upchg=e.chgcd(+)
          and f.cls(+)='6' and a.gdcls9=f.scls1(+)
          and a.ijan=m02.ijan(+)
          and a.mcd = m04.mcd(+)
     order by a.vlin