asp 中查询 oracle数据库 的分页程序,没有用存储过程,效率还可以。 代码如下: '''' 塞北的雪 分页利器(oracle) 不用存储过程 ------------------------- '其中注释中有 ###的需要用户设置 dim tpagesize '页大小 dim ttablename '表或者视图名 dim tfieldlist '查询的字段列表 dim r_count '查得的记录数 '排序处理 if(torderfield="") then torderfield="item_code" ' ### 设置默认排序字段 torder=" order by " & torderfield & " " & torderdirection & " " '生成排序字符串 if(tcurpage="") then tcurpage=1 ' 构造查询条件,根据具体的程序,肯定不一样。但是最后的条件必须是“ where ??? ” if trim(toption)="" then 这就是全部代码,感兴趣的朋友,可以研究一下,或者将他封装起来,加上分页导航等方法。总之,希望此代码能对大家有用。
'其中注释中有 参数传递 ** 的 说明要通过参数 传递。
'定义变量
dim toption '查询条件
dim torder '排序字符串
dim torderfield '排序字段 可通过参数获得:order_field
dim torderdirection '排序方向 可通过参数获得:order_direction
dim ttotalcount '总记录数 可通过参数获得:t_count
dim tpagecount '页数
dim tcurpage '当前页号 可通过参数获得:page
dim tpagefield '用于分页的字段
set rs=server.createobject("adodb.recordset") '记录集对象
torderfield=request("order_field") '获得排序字段(参数传递 **)
torderdirection=request("order_dir") '获得排序方向(参数传递 **)
if(torderdirection="") then torderdirection="asc" ' ### 设置默认排序方向
'定义参数
tpagesize=find_rs_count ' ### 设置页大小
ttablename="view_select1" ' ### 设置与查询的表格或视图
tfieldlist=" * " ' ### 欲查询的字段列表
tpagefield="item_code" ' ### 设置一个主键或唯一索引的字段 ,用于分页计算
'页数处理
tcurpage=request("page") '获得当前页(参数传递 **)
ttotalcount=request("t_count") '获得总页数(参数传递 **)
if(cint(tcurpage)=0) then tcurpage=1
if(tpagecount="") then tpagecount =1
if(cint(tpagecount)=0) then tpagecount=1
toption=" issue_flag='y'" ' ### 设置条件
if f_c<>"" then toption= toption & f_c ' ### 设置条件
toption = " where 1=1 " '如果没有条件,就自己加一个。
else
toption= " where " & toption
end if
'构造查询字符串,这个分页程序的核心,此查询串是我们只下载当前页所需的记录
sss="select * from (select rownum r_n,temptable.* from (select " & tfieldlist & " from " & ttablename & " " & toption & " " & torder & ") temptable ) where r_n between " & cstr((tcurpage -1) * tpagesize +1) & " and " & cstr(tcurpage * tpagesize)
'执行主查询,获得相应记录集
call conndatabase() ' ### 建立数据库连接
rs.cursorlocation=3
rs.open constr,conn,3,1 '执行查询
r_count= rs.recordcount
'当还没有查询过总记录数时 并且 总的记录数超过了页大小时 ,查询当前条件下的总的记录数
if(r_count>=tpagesize or tcurpage>1) and ttotalcount=0 then
set rr=conn.execute("select count(*) from " & ttablename & " " & toption)
ttotalcount=rr(0)
rr.close()
set rr=nothing
end if
if(cint(ttotalcount)=0) then ttotalcount=r_count '如果总记录为0,将当前差得的记录集的记录数设置为总记录数,说明当前的总记录数小于页大小
'利用页大小和总记录数 计算页数
if(cint(ttotalcount)>cint(tpagesize)) then
tpagecount=cint((cint(ttotalcount) \ cint(tpagesize)))
if(cint(ttotalcount) mod cint(tpagesize))>0 then
tpagecount =tpagecount +1
end if
end if
tcurpage=cint(tcurpage)
tpagecount=cint(tpagecount)
' ---------------------------------------------------------------------
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器