select x.*,
	ceil(rnum / :lcnt) as pgno,
	0 chkval,
	max(rnum) over() as maxnum
from (
	select
		ROW_NUMBER() OVER (ORDER BY a.adat,a.vseq,a.jan) as rnum,
		to_char(a.adat, 'yyyy/mm/dd') as adat,
		a.jan,
		a.gdcls9nm,
		a.gdjnm,
		a.gdjstnd,
		a.vseq,
		a.ypno,
		a.cst,
		a.amt,
		to_char(a.cdat, 'yyyy/mm') as cdat,
		a.com1
	from af24cv01 a
	where a.ktktcd=:ktktcd
      and (:ijan is null or a.ijan= :ijan)
	  and (:sdat is null or a.adat>=to_date(:sdat, 'yyyy/mm/dd'))
	  and (:edat is null or a.adat<=to_date(:edat, 'yyyy/mm/dd'))
      and (:spktcd is null or a.spktcd= :spktcd)
	) x
	order by x.rnum
