首页 > 代码库 > Oracle对没有主键的表分页

Oracle对没有主键的表分页

普通情况对于有主键,能够做唯一表识的表。我们能够利用主键和rownum配合实现。比如:

select scott.emp.* 
from scott.emp left join 
        (select empno id, rownum num from scott.emp) id_num 
        on scott.emp.empno = id_num.id 
where id_num.num between 5 and 10;

假设遇到没有主键的表能够尝试rowid取代。rowid不会由于排序或者查询,甚至update都不会改动,因此能够借助这个字段作分页。

select scott.emp.* 
from scott.emp left join 
    (select rowid id, rownum num from scott.emp)  id_num 
    on scott.emp.rowid = id_num.id 
where id_num.num between 5 and 10;
<script type="text/javascript"> $(function () { $(‘pre.prettyprint code‘).each(function () { var lines = $(this).text().split(‘\n‘).length; var $numbering = $(‘
    ‘).addClass(‘pre-numbering‘).hide(); $(this).addClass(‘has-numbering‘).parent().append($numbering); for (i = 1; i <= lines; i++) { $numbering.append($(‘
  • ‘).text(i)); }; $numbering.fadeIn(1700); }); }); </script>

Oracle对没有主键的表分页