select x.*,
	ceil(rnum / :lcnt) as pgno,
	0 chkval,
	max(rnum) over() as maxnum
from (
	select
		ROW_NUMBER() OVER (ORDER BY a.spktcd,a.mcd) as rnum,
		a.spktcd,
		a.ktktnm spktnm,
		a.mcd,
		a.mnm,
		a.amt,
		a.icnt,
		sum(a.amt) over(partition by a.ktktcd) tamt,
		sum(a.icnt) over(partition by a.ktktcd) ticnt,
		a.vseq,
		a.clsnm,
		to_char(a.dat1,'yyyy/mm/dd') dat1,
		to_char(a.dat,'yyyy/mm/dd') dat,
		to_char(a.dat1,'yyyy/mm/dd') ddat1,
		to_char(a.dat,'yyyy/mm/dd') ddat
	from af213v01 a
	where a.ktktcd=:ktktcd
      and (:spktcd is null or a.spktcd=:spktcd)
) x
order by x.rnum
