select x.*,
	ceil(rnum / :lcnt) as pgno,
	0 chkval,
	max(rnum) over() as maxnum
from (
	select
		ROW_NUMBER() OVER (ORDER BY a.mcd) as rnum,
		a.mcd, a.mnm,
		a.modfr,
		decode(a.modfr,0,'FAX発注',-1,'ﾊｳﾈｯﾄ',-2,'プラネット',-3,'井田','設定なし') modfrnm,
		a.mfax  , a.mfax   org_mfax  , 
		a.htpnt1, a.htpnt1 org_htpnt1, 
		a.htpnt2, a.htpnt2 org_htpnt2, 
		a.htlmt1, a.htlmt1 org_htlmt1, 
		a.htlmt2, a.htlmt2 org_htlmt2
	from afm04 a
	where (:mcds is null or a.mcd>=:mcds)
	  and (:mcde is null or a.mcd<=:mcde)
) x
order by x.rnum
