select  a.mcd, m04.mnm,
        a.cuiseq,
        to_char(a.dat,'yyyy/mm/dd') dat,to_char(a.dat1,'yyyy/mm/dd') dat1,
        a.spktcd,b.ktktnm spktnm,a.com1,
        a.iseq,a.vlin,a.jan,a.ijan,c.gdjnm,c.gdjstnd,
        a.mvpno,a.cst,a.com,c.gdcnum,c.gdbnum,
        c.gdcls9,f.scls5 gdcls9nm,c.gdhtun,
        d.chgnm chgcdnm,
        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,
        c.undkbn /*登録時、バラは中チェック用*/
from afm04 m04, afm90 f,afm08 e,afm08 d,afm02 c,afm05 b,afr3111 a
where a.ktktcd=:ktktcd
and a.vseq=:vseq
and a.mcd=:mcd
and a.dcls in ('1','2') and a.dcls1='1'
and a.sts='N'
and a.spktcd=b.ktktcd(+)
and a.ijan=c.ijan(+)
and a.chgcd=d.chgcd(+)
and a.upchg=e.chgcd(+)
and f.cls(+)='6' and c.gdcls9=f.scls1(+)
and a.mcd = m04.mcd(+)
order by a.vlin