select x.*,
	ceil(rnum / :lcnt) as pgno,
	0 chkval,
	max(rnum) over() as maxnum
from (
	select
		ROW_NUMBER() OVER (ORDER BY a.cucd,a.cuscd,a.dat,a.vseq,a.vlin) as rnum,
		a.cucd,
       	a.cuscd,
       	a.cunm,
       	a.spnm,
       	to_char(a.dat, 'yyyy/mm/dd') as dat,
       	a.vseq,
       	a.vlin,
       	a.jan,
       	a.gdcls9nm,
       	a.gdjnm,
       	a.gdjstnd,
       	a.spktcd,
       	a.spktnm,
       	a.pno,
       	a.ypno,
		a.ijan
	from af246v01 a
	where a.ktktcd=:ktktcd
      and (:cucd is null or a.cucd= :cucd)
	  and (:cuscd is null or a.cuscd= :cuscd)
	  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 (:umflg <> '1'
			or (:umflg = '1' and a.umflg = 1))
	) x
	order by x.rnum
