select x.*,
	ceil(rnum / :lcnt) as pgno,
	0 chkval,
	max(rnum) over() as maxnum
from (
	select
		ROW_NUMBER() OVER ( $$ORD_STR$$ ) as rnum,
		sum(a.pno1) over (partition by a.wseq) tpno,
		sum(a.pno10) over (partition by a.wseq) tamt,
		count(b.jan) over (partition by a.wseq) titem,
		b.jan,
		to_char(a.dat1,'yyyy/mm/dd') dat1,
		c.scls5 gdcls9,
		b.gdjnm,
		b.gdjstnd,
		a.pno1,
		a.pno2,
		a.pno3,
		a.pno4,
		a.pno5,
		a.pno6,
		a.pno7,
		a.pno8,
		a.pno9,
		a.pno10 amt,
		a.pno11,
		a.pno51,
		a.ijan
	from afm90 c,afm02 b,afw851 a
	where a.wseq=:wseq 
	  and a.cls='4'
	  and a.ijan=b.ijan(+)
	  and c.cls(+)='6' and b.gdcls9=c.scls1(+)
	  and (nvl(:gdcls9,'-1') = '-1' or b.gdcls9=:gdcls9)
	  and (:brand is null or b.brand=:brand)
) x
order by x.rnum
