select a.*,
to_char(a.taxrtd, 'yyyy/mm/dd') as d_taxrtd,
to_char(a.rldat, 'yyyy/mm/dd') as d_rldat,
to_char(a.dsdat, 'yyyy/mm/dd') as d_dsdat,
to_char(a.gdreg, 'yyyy/mm/dd hh24:mi') as d_gdreg,
to_char(a.gdupd, 'yyyy/mm/dd hh24:mi') as d_gdupd,
to_char(a.gdstp, 'yyyy/mm/dd hh24:mi') as d_gdstp,
m90.scls5 as gdcls9nm,
decode(a.gdstp, null, '0', '1') as stpflg
from afm90 m90, afm02 a
where (
    (:kbn = '1' and a.jan = :inpcd)
    or (:kbn = '2' and a.vjan = :inpcd)
    or (:kbn = '3' and a.jan like '%'||:inpcd)
    or (:kbn = '9' and a.ijan = :inpcd)
  )
  and m90.cls(+) = '6' and a.gdcls9=m90.scls1(+)
