select x.*,
	ceil(rnum / :lcnt) as pgno,
	0 chkval,
	max(rnum) over() as maxnum
from (
	select
		ROW_NUMBER() OVER (ORDER BY a.vseq,a.vlin) as rnum,
		a.iseq iseq3111,a.mcd spktcd, d.ktktnm spktnm,
		a.cuiseq,a.vseq,a.vlin,to_char(a.dat,'yyyy/mm/dd') dat,
		a.jan,a.ijan,b.gdjnm,b.gdjstnd,b.gdcls9,c.scls5 gdcls9nm,
		a.mvpno,a.jpno,a.nrld,
		to_char(a.dat,'yyyy/mm/dd') old_dat
		/*a.pno ord_pno,a.pno*/ /*画面に埋めなくてよいっぽい？*/
	from afm05 d,afm90 c,afm02 b,afr3111 a
	where a.cls='11' and a.ceslip1='2' and a.ceslip2='10'
		and a.ktktcd=:ktktcd
		and a.spktcd=:spktcd1
		and ((:spktcd2 is null) or (a.mcd=:spktcd2))
		and ((:cuiseq is null) or (a.cuiseq=:cuiseq))
		and ((:vseq is null) or (a.vseq=:vseq))
		and a.sts=' '
		and a.nrld>0
		and a.ijan=b.ijan(+)
		and c.cls(+)='6' and b.gdcls9=c.scls1(+)
		and a.mcd=d.ktktcd(+)
) x
order by x.rnum
