WITH select_rownum AS
(SELECT MAX(a.Row_Number) AS max_rownum
FROM (SELECT Row_Number() over()
FROM hoge_table
WHERE hoge_table.hoge_id=$P{hoge}) a
)
SELECT
main.Line,
main.Name,
FROM (SELECT generate_series(1,case when mod(select_rownum.max_rownum,12) > 0 then ((select_rownum.max_rownum) / 12 + 1) * 12
else select_rownum.max_rownum
END) AS CNT from select_rownum) GENE
LEFT OUTER JOIN
(SELECT
row_number() over(),
hoge_table.Line,
mhoge.Name
FROM hoge_table
LEFT OUTER JOIN M_hoge mhoge ON(hoge_table.M_hoge_ID=mhoge.M_hoge_ID)
WHERE hoge_table.hoge_ID=$P{hoge}) main
ON GENE.CNT = main.row_number
ORDER BY Line