select
  a.prop,
  a.spktcd,
  m05.ktktnm as spktnm,
  a.viseq,
  a.vlin,
  to_char(a.dat2, 'yyyy/mm/dd') as dat2,
  to_char(a.adat, 'yyyy/mm/dd') as adat,
  a.dcubcd,
  a.cuslip,
  a.bbno,
  a.dtxt1,a.dtxt2,
  a.ltxt1,a.ltxt2,
  a.iseq30,
  a.piseq,
  a.ijan,
  b.jan,
  b.gdjnm,
  b.gdjstnd,
  b.gdcls9,
  c.scls5 gdcls9nm,
  a.jpno,
  a.tpno,
  a.ncst,
  a.sal,
  a.fcst as gdcst,
  decode(a.jmcat,'1',null,'2','サンプル・交換品','3','添付品',null) jmcatnm,
  to_char(a.dat3, 'yyyy/mm/dd') as dat3,
  to_char(a.dat4, 'yyyy/mm/dd') as dat4,
  a.hvseq,
  d.chgnm chgcdnm,
  to_char(a.idat, 'yyyy/mm/dd hh24:mi:ss') as 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,
  a.txt1,
  decode(b.jan,null,a.gdjnm,b.gdjnm) gdjnm2,
  decode(b.jan,null,a.gdjstnd,b.gdjstnd) gdjstnd2,
  decode(nvl(g.cls1,'0'),'1',nvl(j.snum1,i.snum1),i.snum1) vno,
  k.snum1,
  a.ntcst,
  case when :cutaxcls = '1' and :cutax = '1' then a.ntcst
  else a.ncst end as dsp_ncst,
  h.cunm, m032.spnm,
  g.vseq as cvseq,
  g.cuiseq
from afm05 m05, afm032 m032,
  afm90 k,afm90 j,afm90 i,afm03 h,afr3123 g,axm99 f,afm08 e,afm08 d,afm90 c,afm02 b,aur32 a
where a.ktktcd=:ktktcd
    and a.vseq=:vseq
    and a.cucd=:cucd
    and ( (:cuscd is null and a.cuscd is null) or (:cuscd is not null and a.cuscd=:cuscd ) )
    and a.dcls='1' and a.tcls=:tcls
    and a.sts=0
    and a.ktktcd=f.ktktcd
    and ((:sts='3') or (:sts<>'3' and a.sbat2>=f.sbat2))
    and (a.sbat>=:sbat or a.sbat=-999)
    and a.viseq=:viseq
    and a.ijan=b.ijan(+)
    and c.cls(+)='6' and b.gdcls9=c.scls1(+)
    and a.chgcd=d.chgcd(+)
    and a.upchg=e.chgcd(+)
    and a.piseq=g.iseq(+)
    and a.cucd=h.cucd(+)
    and a.cucd=m032.cucd(+) and a.cuscd=m032.cuscd(+)
    and i.cls(+)='9' and h.cudenp1=i.scls1(+)
    and j.cls(+)='9' and h.cudenp2=j.scls1(+)
    and k.cls(+)='C' and b.gdcls6=k.scls1(+)
    and a.spktcd = m05.ktktcd(+)
  order by a.vlin
