select x.*,
	ceil(rnum / :lcnt) as pgno,
	0 chkval,
	max(rnum) over() as maxnum
from (
	select
		ROW_NUMBER() OVER (ORDER BY a.dat,a.vseq,a.vlin) as rnum,
		to_char(a.dat, 'yyyy/mm/dd') as dat,
		a.mcd,
		a.mnm,
		a.vseq,
		a.vlin,
		a.jan,
		a.gdcls9nm,
		a.gdjnm,
		a.gdjstnd,
		a.spktcd,
		a.spktnm,
		a.pno
	from af245v01 a
	where a.ktktcd=:ktktcd
      and (:mcd is null or a.mcd= :mcd)
	  and (:ijan is null or a.ijan= :ijan)
	  and (:sdat is null or a.dat>=to_date(:sdat, 'yyyy/mm/dd'))
	  and (:edat is null or a.dat<=to_date(:edat, 'yyyy/mm/dd'))
      and (:spktcd is null or a.spktcd= :spktcd)
      and (:vseq is null or a.vseq= :vseq)
	) x
	order by x.rnum
