<?php

function get_limit_sql($sql,$min,$max){

    return "SELECT * FROM ( SELECT row_.*,rownum rownum_ FROM ($sql) row_ where rownum <=$max) where rownum_>$min";

}

?>