一个ORACLE分页程序 挺实用的.

2016-01-29 14:42 3 1 收藏

一个ORACLE分页程序 挺实用的.,一个ORACLE分页程序,挺实用的.

【 tulaoshi.com - PHP 】

  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"
<HTML
<HEAD
<TITLEPaging Test</TITLE
<META NAME="Generator" CONTENT="TextPad 4.0"
<META NAME="Author" CONTENT="?"
<META NAME="Keywords" CONTENT="?"
<META NAME="Description" CONTENT="?"
</HEAD

<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#FF0000" VLINK="#800000" ALINK="#FF00FF" BACKGROUND="?"
<?php

// How to split the result into pages, like 'limits' in MySQL?
// ===========================================================
// Tutorial by Neil Craig (neilc@netactive.co.za)
// Date: 2001-06-05
// With this example, I will explain paging of database queries where the
// result is more than the developer want to print to the page, but wish to
// split the result into seperate pages.
// The table "SAMPLE_TABLE" accessed in this tutorial has 4 fields:
// PK_ID, FIELD1, FIELD2 and FIELD3. The types don't matter but you should
// define a primary key on the PK_ID field.

$display_rows = 5;     // The rows that should be display at a time. You can
                       // modify this if you like.

// Connect to the Oracle database
putenv("ORACLE_SID=purk");
putenv("ORACLE_HOME=/export/oracle8i");
putenv("TNS_ADMIN=$ORACLE_HOME/network/admin");
$OracleDBConn = OCILogon("purk","purk","lengana.world");

// This query counts the records
$sql_count = "SELECT COUNT(*) FROM SAMPLE_TABLE";

// Parse the SQL string & execute it
$row_count=OCIParse($OracleDBConn, $sql_count);       
OCIExecute($row_count);

// From the parsed & executed query, we get the amount of records found.
// I'm not storing this result into a session variable because it allows for
// new records to be shown as it is entered by another user while the result
// is printed.
if (OCIFetch($row_count)) {
    $num_rows = OCIResult($row_count,1);
} else {
    $num_rows = 0;        // If no record was found
}

// Free the resources that were used for this query
OCIFreeStatement($row_count);

// We need to prepare the query that will print the results as a page. I will
// explain the query to you in detail.

// If no page was specified in the url (ex. http://mysite.com/result.php?page=2),
// set it to page 1.
if (empty($page) || $page == 0) {
    $page = 1;
}

// The start range from where the results should be printed
$start_range = (($page - 1) * $display_rows) + 1;

// The end range to where the results should be printed
$end_range = $page * $display_rows;

// The main query. It consists of 3 "SELECT" statements nested into each
// other. The center query is the query you would normally use to return the
// records you want. Do you ordering and "WHERE" clauses in this statement.
// We select the rows to limit our results but because the row numbers are
// assigned to the rows before any ordering is done, lets the code print the
// result unsorted.
// The second nested "SELECTED" assigns the new row numbers to the result
// for us to select from.

$sql = "SELECT PK_ID, FIELD1, FIELD2, FIELD3, ROW_NO FROM (SELECT PK_ID, ";
$sql .= "FIELD1, FIELD2, FIELD3, ROWNUM ROW_NO FROM (SELECT PK_ID, FIELD1, ";
$sql .= "FIELD2, FIELD3 FROM SAMPLE_TABLE ORDER BY FIELD3)) WHERE ROW_NO BETWEEN ";
$sql .= $start_range." AND ".$end_range;

来源:https://www.tulaoshi.com/n/20160129/1493986.html

延伸阅读
标签: ASP
  /*****听以前的同事说asp页面上的分页太慢了(如果数据多了), 就想了这么个笨办法。有些地方还要考虑----比如select top 22 * from cat_list where T_id not in (select T_id from #change)是否有效率问题;数据不能重复等等 不过灵活性挺好。希望各位高手再给帮忙改正;多谢chair3的帮助---这个存储过程还可以在加入几个变量,随便...
标签: ASP
<%''本程序文件名为:Pages.asp% <%''包含ADO常量表文件adovbs.inc,可从"\Program Files\Common Files\System\ADO"目录下拷贝% <!--#Include File="adovbs.inc"-- <%''*建立数据库连接,这里是Oracle8.05数据库 Set conn=Server.CreateObject("ADODB.Connection") conn.Open "Provider=msdaora.1;Data Source=YourSrcName;User ...
create proc sp_PublicTurnPageWebSite( @TBName nvarchar(100)='', --表名,如 pinyin @PageSize int=10, --每页的记录数,默认为 10 @CurPage int=1, --表示当前页 1 @KeyField nvarchar(100)='ID', --关键字段名,默认为 ID,该字段要求是表中的索引 或 ...
代码如下: ------------------------------------ --用途:分页存储过程(对有主键的表效率极高) --说明: ------------------------------------ ALTER PROCEDURE [UP_GetRecordByPage] @tblName varchar(255), -- 表名 @fldName varchar(255), -- 主键字段名 @PageSize int = 10, -- 页尺寸 @PageIndex int = 1, -- 页码 @IsReCoun...
标签: PHP
  这个分页函数非常高只能的 看看就知道了 function ppage($total, $page, $e_page = 15, $e_block = 10, $url = '', $color = '') { if(!strpos($url,'?'))    $url.='?'; else    $url.='&'; if($color<'') {    $color   ='<font color='.$color.''...