asp + oracle 分页方法 (不用存储过程)

news/2024/7/10 22:09:09 标签: oracle, 存储, asp, 数据库, c
cle class="baidu_pl">
cle_content" class="article_content clearfix">
content_views" class="htmledit_views">

class="tags" href="/tags/ASP.html" title=asp>asp 中查询 class="tags" href="/tags/ORACLE.html" title=oracle>oracleclass="tags" href="/tags/ShuJuKu.html" title=数据库>数据库 的分页程序࿰c;没有用class="tags" href="/tags/CunChu.html" title=存储>存储过程࿰c;效率还可以。

代码如下:

''''  塞北的雪  分页利器(class="tags" href="/tags/ORACLE.html" title=oracle>oracle)  不用class="tags" href="/tags/CunChu.html" title=存储>存储过程   -------------------------

'其中注释中有 ###的需要用户设置
'其中注释中有 参数传递 ** 的 说明要通过参数 传递。


'定义变量
dim tOption                  '查询条件
dim tOrder                   '排序字符串     
dim tOrderField              '排序字段        可通过参数获得:order_field
dim tOrderDirection          '排序方向        可通过参数获得:order_direction

dim tPageSize                '页大小
dim tTotalCount              '总记录数        可通过参数获得:t_count
dim tPageCount               '页数
dim tCurPage                 '当前页号        可通过参数获得:page

dim tTableName               '表或者视图名

dim tFieldList               '查询的字段列表
dim tPageField               '用于分页的字段

dim r_count                  '查得的记录数


set rs=server.createobject("adodb.recordset")        '记录集对象

'排序处理
tOrderField=Request("order_field")                   '获得排序字段(参数传递 **)
tOrderDirection=Request("order_dir")                 '获得排序方向(参数传递 **)

if(tOrderField="") then tOrderField="item_code"       ' ### 设置默认排序字段
if(tOrderDirection="") then tOrderDirection="asc"     ' ### 设置默认排序方向

tOrder=" order by " & tOrderField & " " & tOrderDirection & " "   '生成排序字符串


'定义参数
tPageSize=find_rs_count        ' ### 设置页大小
tTableName="view_select1"      ' ### 设置与查询的表格或视图
tFieldList=" * "               ' ### 欲查询的字段列表
tPageField="item_code"         ' ### 设置一个主键或唯一索引的字段 ࿰c;用于分页计算


'页数处理
tCurPage=Request("page")             '获得当前页(参数传递 **)
tTotalCount=Request("t_count")       '获得总页数(参数传递 **)

if(tCurPage="") then tCurPage=1
if(cint(tCurPage)=0) then tCurPage=1
if(tPageCount="") then tPageCount =1
if(cint(tPageCount)=0) then tPageCount=1

' 构造查询条件࿰c;根据具体的程序࿰c;肯定不一样。但是最后的条件必须是“ where ??? ”
tOption=" issue_flag='Y'"                      ' ### 设置条件
if f_c<>"" then tOPtion= tOPtion & f_c         ' ### 设置条件

if trim(tOption)="" then
     tOption = " where 1=1 "   '如果没有条件࿰c;就自己加一个。
else
     tOption= " where " & tOPtion
end if

   
  
     '构造查询字符串࿰c;这个分页程序的核心࿰c;此查询串是我们只下载当前页所需的记录
 
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)  
 
 '执行主查询࿰c;获得相应记录集
 Call ConnDataBase()                     '  ### 建立class="tags" href="/tags/ShuJuKu.html" title=数据库>数据库连接
    rs.cursorlocation=3
    rs.open conStr,conn,3,1                 '执行查询
    r_count= rs.recordcount


   '当还没有查询过总记录数时 并且 总的记录数超过了页大小时 ࿰c;查询当前条件下的总的记录数
   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࿰c;将当前差得的记录集的记录数设置为总记录数࿰c;说明当前的总记录数小于页大小
  
   '利用页大小和总记录数 计算页数
   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)


'  ---------------------------------------------------------------------

        这就是全部代码࿰c;感兴趣的朋友࿰c;可以研究一下࿰c;或者将他封装起来࿰c;加上分页导航等方法。总之࿰c;希望此代码能对大家有用。


cle>

http://www.niftyadmin.cn/n/658546.html

相关文章

【RL-TCPnet网络教程】第25章 DHCP动态主机配置协议基础知识

第25章 DHCP动态主机配置协议基础知识 本章节为大家讲解DHCP&#xff08;Dynamic Host Configuration Protocol&#xff0c;动态主机配置协议&#xff09;&#xff0c;通过前面章节对TCP和UDP的学习&#xff0c;需要大家对DHCP也有个基础的认识。 &#xff08;本章的知识点…

基于百度LAC2.0的词云图生成——各大分词工具实战比较

1.前言 词法分析是自然语言处理的基本工具&#xff0c;主要包括分词、词性标注和实体识别等功能。目前各类词法分析工具大行其道&#xff0c;有免费开源的&#xff0c;也有商业收费的&#xff1b;有高校研发的&#xff0c;也有企业开发的&#xff1b;有支持Java的&#xff0c;…

python中的逻辑运算符优先级比较——串连特性

1.背景 昨天&#xff0c;在日常代码中&#xff0c;我发现了一件不可思议的事情。简化之后&#xff0c;代码可以描述为 5 > 3 is True令我万万没想到的是&#xff0c;这个表达式的值竟然是False 我首先想到&#xff0c;可能是因为优先级而导致的结合律应用问题。但是对于…

nginx的安装部署

安装环境准备 一. gcc 安装 安装 nginx 需要先将官网下载的源码进行编译&#xff0c;编译依赖 gcc 环境&#xff0c;如果没有 gcc 环境&#xff0c;则需要安装&#xff1a;yum install gcc-c 二. PCRE pcre-devel 安装 PCRE(Perl Compatible Regular Expressions) 是一个Perl库…

【Springboot】Springboot整合Thymeleaf模板引擎

Thymeleaf Thymeleaf是跟Velocity、FreeMarker类似的模板引擎&#xff0c;它可以完全替代JSP&#xff0c;相较与其他的模板引擎&#xff0c;它主要有以下几个特点&#xff1a; 1. Thymeleaf在有网络和无网络的环境下皆可运行&#xff0c;即它可以让美工在浏览器查看页面的静态效…

一段保留滚动状态的js代码

<!-- writed by sll updated by northsnow --><script languagejavascript> var PatInt/^/d$/; //验证整数数字 /** * 去左右空格函数 * 参数 str 是一字符串 * 返回 去左右空格的字符串 */function _trim(str){ var ss""str return (…

数据结构队列顺序存储代码实现(C语言)

队列是先入先出的&#xff0c;即先入队的数据先出队 下面程序是队列的顺序存储结构的实现&#xff0c;具有入队&#xff0c;出队&#xff0c;求队列长度的的功能 程序开头 #include <stdio.h> #include <stdlib.h>#define MAXSIZE 100 #define Ok 1 #define ERRO…

虚拟机Linux共享文件夹设置

1.打开虚拟机界面&#xff0c;并启动linux 2.选中上方功能栏中的虚拟机&#xff0c;选中设置 3.点击CD/DVD(SATA)&#xff0c;看到右边有一个使用IOS镜像文件 4.路径填写安装这个虚拟机用的镜像文件路径 然后在选项里选择共享文件夹&#xff0c;右边选择总是启用&#xff0c;添…