如何在特定限制内记录Oracle 10g Express版本中的记录?

时间:2017-02-19 06:57:49

标签: php oracle codeigniter

我使用的是Oracle 10g快递版。我已将它与codeigniter相关联。

我想每页获取10条记录以显示记录。

这是表tbl_language: -

LANGUAGE_ID | LANGUAGE_TITLE | LANGUAGE_ADD_DATE | LANGUAGE_STATUS  |
=====================================================================
      1     |     Hindi      |    18-FEB-17      |        1         |
      2     |     English    |    18-FEB-17      |        1         |
      3     |     Bangla     |    18-FEB-17      |        1         |

现在,我正在使用以下查询

"SELECT * FROM 
       (SELECT fetch.*, rownum rnum FROM 
             (SELECT * FROM tbl_language 
                WHERE language_id > 0 
                ORDER BY TO_CHAR(language_add_date, 'YYYY-MM-DD HH24:MI:SS') 
               DESC) 
       fetch)"

它以下列方式提供数据: -

LANGUAGE_ID | LANGUAGE_TITLE | LANGUAGE_ADD_DATE | LANGUAGE_STATUS  | RNUM
===============================================================================
      3     |     Bangla     |    18-FEB-17      |        1         |   1
      2     |     English    |    18-FEB-17      |        1         |   2
      1     |     Hindi      |    18-FEB-17      |        1         |   3

现在,我正在修改查询两个选择特定行数(类似于使用限制) -

"SELECT * FROM 
    (SELECT fetch.*, rownum rnum FROM 
        (SELECT * FROM tbl_language WHERE language_id > 0 ORDER BY TO_CHAR(language_add_date, 'YYYY-MM-DD HH24:MI:SS') DESC) 
    fetch WHERE rownum >= 1 AND rownum < 2) "

返回一行。 然后我修改了查询

"SELECT * FROM 
    (SELECT fetch.*, rownum rnum FROM 
        (SELECT * FROM tbl_language WHERE language_id > 0 ORDER BY TO_CHAR(language_add_date, 'YYYY-MM-DD HH24:MI:SS') DESC) 
    fetch WHERE rownum >= 2 AND rownum < 3) "

它返回空结果。我做错了什么?

1 个答案:

答案 0 :(得分:0)

在这里。答案在你的帖子中:

"SELECT * FROM 
    (SELECT fetch.*, rownum rnum FROM 
        (SELECT * FROM tbl_language WHERE language_id > 0 ORDER BY TO_CHAR(language_add_date, 'YYYY-MM-DD HH24:MI:SS') DESC) 
    fetch WHERE rownum >= 1 AND rownum < 11) "

我基本上改变了你的条件下rownum的范围(即[1,10])。