select x.*,
	ceil(rnum / :lcnt) as pgno,
	0 chkval,
	max(rnum) over() as maxnum
from (
	select
		ROW_NUMBER() OVER (ORDER BY dat desc,vseq,cls,ceslip1,ceslip2,spktcd) as rnum,
		to_char(a.dat,'yyyy/mm/dd') dat,
		a.vseq,
		a.ijan,
		a.spktcd,
		a.spktnm,
		a.clsnm,
		a.nm1,
		a.nm2,
		a.pno1,
		a.pno2,
		a.pno3,
		a.pno4,
		a.pno5,
		a.pno6,
		a.pno7
	from af291v01 a
	where a.ktktcd=:ktktcd
		and (:spktcd is null or a.spktcd=:spktcd)
		and a.ijan=:ijan
	) x
	order by x.rnum
