select x.*,
	ceil(rnum / :lcnt) as pgno,
	max(rnum) over() as maxnum
from (
	select
		ROW_NUMBER() OVER (ORDER BY adat,dcls,vseq,vlin) as rnum,
		to_char(a.adat,'yyyy/mm/dd') adat,
		a.vseq,
		a.vlin,
		a.cls,
		a.jan,
		a.gdcls9 gdcls9nm,
		a.gdjnm,
		a.gdjstnd,
		a.tpno,
		a.ncst,
		a.amt,
		a.txt2 com,
		a.spktcd,
		a.spktnm,
		sum(a.tpno) over() as ttpno,
		sum(a.amt) over() as tamt
	from af283v03 a
	where a.ktktcd=:ktktcd
		and a.adat>=to_date(:adats,'yyyy/mm/dd')
		and a.adat<=to_date(:adate,'yyyy/mm/dd')
		and (:mcd is null or a.mcd=:mcd)
		and (:vseq is null or a.vseq=:vseq)
		and (:viseq is null or a.viseq=:viseq)
		and (:ijan is null or a.ijan=:ijan)
		and (	(nvl(:cls,'000') = '000') /*全て*/
			or
			(:cls = '101'  and dcls='3' and tcls in ('11','31')) /*仕入*/
			or
			(:cls = '102'  and dcls='3' and tcls='21') /*返品*/
			or
			(:cls = '103'  and dcls='3' and tcls='13') /*値引*/
			or
			(:cls = '299'  and dcls='4') /*入金*/
			)
) x
order by x.rnum
