按照你的规则,提取出全部数据,然后:
在asp.net里面: private void DataGrid2_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
SaveData mynews = new SaveData();
String Strsql = "select * from tab_new where classid='5' order by id desc";
DataGrid2.DataSource=mynews.ShowNews(Strsql);
DataGrid2.CurrentPageIndex=e.NewPageIndex;
Page.DataBind();
}
你自己不用去关心它如何去取下面的n条数据。

解决方案 »

  1.   

    根据order by各个字段而进行分页排序,那就在你前端开发完的。
    如:可以前端用一个下拉框选择以那个字段进行排序
    "select * from table_name order by "+变量;
      

  2.   

    如果用(order by name):
       select * from (select rownum rm,a.* from table_name a order by name) where rm<=n and rm>=m;
       查询20万条记录的分页显示(10秒),和不用order by查询()0.89秒,时间相差5--6倍。该怎么办呢?速度太慢了??????????????????????????????????????????????
        必须得用order by,怎样提高速度呢???????????????????????????????????????????????????
      

  3.   

    你在jsp叶面中自然是有页数的,还有每一页有多少条数据,这些在jsp页面中写好,当作参数传入oracle的过程。过程主要部分如下:select * from (
    select rownum r,...... from tbname)
    where r between (页号-1)*页显示数
     and 页号*页显示数;你在jsp中调用过程就可以了,这样做既灵活又高效。没问题的。
      

  4.   

    nicholaz(九思·逢尤)
       谢谢
        select * from (select rownum id,a.* from people a order by name) where id between 变量1 and 变量2;   根据我的问题能否给我写一个oracle的过程,我不太会写oracle过程。我需要传两个参数(变量1、变量2)
       能否给个oralce过程具体的代码,过程执行后返回一个查询的结果集。
       请您帮帮我吧!!!!!!!!!!
        等等
      

  5.   

    create or replace package test
    as
    type ref_cursor is ref cursor;
    function get_page_by_search(
    v_sel_condition  in varchar2,      n_page_id in number,
         n_list_num   in number --  每页显示的记录条数
    ) return ref_cursor;
    end;create or replace package body test
    as
    function get_page_by_search(
    v_sel_condition  in varchar2,      n_page_id in number,
         n_list_num   in number --  每页显示的记录条数
    ) return ref_cursor;
    is      
    rc ref_cursor;
    begin 
    open rc for select * from (select rownum id,a.* from people a order by name) where id between 变量1 and 变量2;
    return rc;  
    exception
    when others then
    if rc%isopen then
    close rc;
    end if;
    end;
      

  6.   

    你在jsp中调用  test.get_page_by_search(... , ...);就可以了
      

  7.   

    建立people表的name字段索引可改善查询性能。
      

  8.   

    张波:
        您好,为什么我作的包创建时出现如下错误提示“警告: 创建的包带有编译错误。”
      代码如下:
      create or replace package test
    as
    type ref_cursor is ref cursor;
    function get_page_by_search(v_sel_condition in varchar2,v_curpage in number,v_list_num in number) return ref_cursor;
    end;create or replace package body test
    as
    function get_page_by_search(v_sel_condition in varchar2,v-curpage in number,v_list_num in number) return ref_cursor;
    is      
    rc ref_cursor;
    begin 
     open rc for select * from (select rownum id,a.* from people a order by name) where id between (v_curpage-1)*v_list_num and v_curpage*v_list_num;
     return rc;  
    exception
    when others then
    if rc% is open then
    close rc;
    end if;
    end;
      

  9.   

    呵呵!这里写错了一个,将 _ 写成 ‘ - ‘了function get_page_by_search(v_sel_condition in varchar2,v-curpage in 改称function get_page_by_search(v_sel_condition in varchar2,v_curpage in
      

  10.   

    你将 package body 改称create or replace package body test
    as
    function get_page_by_search(v_sel_condition in varchar2,
    v_curpage  in number,
    v_list_num in number) return ref_cursor
    is      
    rc ref_cursor;
    begin 
     open rc for select * from (select rownum id,a.* from people a order by name) where id between (v_curpage-1)*v_list_num and v_curpage*v_list_num;
     return rc;  
    exception
    when others then
    if rc %isopen then
    close rc;
    end if;
    end get_page_by_search;
    end test;
      

  11.   

    是这样吧!!
        create or replace package test
    as
    type ref_cursor is ref cursor;
    function get_page_by_search(v_sel_condition in varchar2,v_curpage in number,v_list_num in number) return ref_cursor;
    end;create or replace package body test
    as
    function get_page_by_search(v_sel_condition in varchar2,
    v_curpage  in number,
    v_list_num in number) return ref_cursor
    is      
    rc ref_cursor;
    begin 
     open rc for select * from (select rownum id,a.* from people a order by name) where id between (v_curpage-1)*v_list_num and v_curpage*v_list_num;
     return rc;  
    exception
    when others then
    if rc %isopen then
    close rc;
    end if;
    end get_page_by_search;
    end test;
    您能不能试一下?
    我试了还不行,提示同上?
       真的很麻烦您了!
      

  12.   

    SQL> create table PEOPLE(
      2  NAME VARCHAR2(30)  not null,
      3  ADDRESS VARCHAR2(50)  not null,
      4  TEL VARCHAR2(30)  not null,
      5  FAX VARCHAR2(30)  not null,
      6  EMAIL VARCHAR2(50)  not null,
      7  constraint PK_PEOPLE primary key (NAME)
      8  );Table createdSQL> 
    SQL>  create or replace package test
      2  as
      3   type ref_cursor is ref cursor;
      4   function get_page_by_search(v_sel_condition in varchar2,v_curpage in number,v_list_num in number) return ref_cursor;
      5  end;
      6  /Package createdSQL> 
    SQL> create or replace package body test
      2  as
      3  function get_page_by_search(v_sel_condition in varchar2,
      4  v_curpage  in number,
      5  v_list_num in number) return ref_cursor
      6  is
      7   rc ref_cursor;
      8  begin
      9   open rc for select * from (select rownum id,a.* from people a order by name) where id between (v_curpage-1)*v_list_num and v_curpage*v_list_num;
     10   return rc;
     11  exception
     12   when others then
     13   if rc %isopen then
     14   close rc;
     15   end if;
     16  end get_page_by_search;
     17  end test;
     18  /Package body created没有问题啊!
      

  13.   

    谢谢:
        特别感谢张波!
        程序包和程序主体已建立!
        在jsp中如何调用程序包,而后使用使用程序包返回的值呢?
        又要麻烦您了
        对不起
        我的信箱:[email protected]
        真的十分感谢!!
      

  14.   

    在jsp中调用包和调用过程是差不多的!只是要返回个结果集而已!我大概给你写一个,你既然是用jsp的应该明白的!String query = "begin :1 := test.get_page_by_search(:2,:3,:4); end;";
          cstmt = conn.prepareCall(query);
          cstmt.registerOutParameter(1,OracleTypes.CURSOR);
          cstmt.setInt(2,...);
         .........
          cstmt.execute();
          rset = (ResultSet)cstmt.getObject(1);
          if(rset.next()){
    ......     //循环取值
    }
    .........
      

  15.   

    张波:
         您好,已经用jsp调程序包实现,但还是比较慢,可否再改造一下,有了order by name(主键),太慢了
       是否可以在优化!!!
       谢谢!
      

  16.   

    你在name上建立一个索引,可以提高速度。
      

  17.   

    nicholaz(九思·逢尤): 
      您好!
      谢谢您的帮助!name是主键如何在其上建索引?
      我也试图在name上建索引,但失败了!
      等您回音!
      

  18.   

    name是主键就已经建立索引了,不用再建了。
      

  19.   

    bzszp(SongZip):
        您好:谢谢您的关注!
        如何分区,(或按照某范围保存到不同的表里面)
    每个分区保存2-5万条? 我没用过,能否具体说一下,一旦可以马上揭贴!
        我的信箱:[email protected]
       
      

  20.   

    CREATE TABLE sales
        ( invoice_no NUMBER, 
          sale_year  INT NOT NULL,
          sale_month INT NOT NULL,
          sale_day   INT NOT NULL )
      PARTITION BY RANGE (invoice_no)
        ( PARTITION sales_q1 VALUES LESS THAN (20000) 
            TABLESPACE tsa,
          PARTITION sales_q2 VALUES LESS THAN (40000) 
            TABLESPACE tsb,
          PARTITION sales_q3 VALUES LESS THAN (60000) 
            TABLESPACE tsc,
          PARTITION sales_q4 VALUES LESS THAN (80000) 
            TABLESPACE tsd 
    ...);
      

  21.   

    我小插几句:
        这种情况下我怎样知道总共的结果数呢?我想在页面上放一个“共 页”;请教!
        (我用的是java)
      

  22.   

    bzszp(SongZip) :
       您好,如何建立用户scott的表空间tsa、tsb、tsc、、、
       分区和表空间有什么区别??
       谢谢!
      

  23.   

    Create a tablespace.Syntax:   CREATE TABLESPACE tablespace_name
          DATAFILE Datafile_Options Storage_Options ;Datafile_Options:    'filespec' [AUTOEXTEND OFF]
        'filespec' [AUTOEXTEND ON [NEXT int K | M] [MAXSIZE int K | M]]
    The Autoextend Maxsize clause will default to UNLIMITED if no value is specified. Storage_Options:    DEFAULT STORAGE storage_clause
        MINIMUM EXTENT int {K|M}
        LOGGING | NOLOGGING
        ONLINE | OFFLINE
        PERMANENT | TEMPORARY
        EXTENT MANAGEMENT {DICTIONARY |
           LOCAL {AUTOALLOCATE | UNIFORM [SIZE int K | M]} }
      

  24.   

    CREATE TABLESPACE tsa DATAFILE ‘/u1/oradata/sales/sales1999_q1.dat’ SIZE 100M DEFAULT STORAGE (INITIAL 30m NEXT 30m MINEXTENTS 3 PCTINCREASE 0) 
      

  25.   

    表存放在表空间里面
    可以把一个表放在一个表空间里,也可以放在多个表空间里
    create index indexname on tbname(name) local;