select x.*,
	ceil(rnum / :lcnt) as pgno,
	0 chkval,
	max(rnum) over() as maxnum
from (
	select
		ROW_NUMBER() OVER (ORDER BY a.chgcd) as rnum,
		a.chgcd, a.chgnm, a.chgpas,
        to_char(a.hdat,'yyyy/mm/dd hh24:mi:ss') hdat,
        a.sts,
        decode(a.sts,'0','使用可','1','ロック中') stsnm,
        decode(a.sts,'1','パスワード'||to_char(b.rcnt)||'回連続失敗','') com,
        decode(a.sts,'0','blue','1','red','') color
from axm99 b, afm08 a
where b.ktktcd=:ktktcd
  and (:chgcds is null or a.chgcd>=:chgcds)
  and (:chgcde is null or a.chgcd<=:chgcde)
  and (:rdo_sts='0' or (:rdo_sts='1' and a.sts='0') or (:rdo_sts='2' and a.sts='1'))
  and a.chgstp is null
	) x
order by x.rnum
