WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search


Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder



Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : How to limit the number of records returned by an ORACLE query?
Categories : Databases, Oracle
Boaz Yahav
Date : Dec 21st 1999
Grade : 3 of 5 (graded 2 times)
Viewed : 87053
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Boaz Yahav
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

Oracle SQL does not support anything like LIMIT in MySQL. You can just limit the
number of rows returned with rownum. So if you only want the first ten
records use:

SELECT * FROM table WHERE ROWNUM<10;

However the following won't work:

SELECT * FROM table WHERE ROWNUM>90 AND ROWNUM<100;

This is because Oracle checks for the first row and the condition is false,
as the rownum would be 1. So this row is not returned, thus the rownum is
still 0. So the rownum will never get to 90.

You can try :

SELECT * FROM table WHERE ROWNUM<101;
minus
SELECT * FROM table WHERE ROWNUM<91;



Connecting to Oracle with php3
Categories : Oracle, PHP, Databases
A database abstraction layer for the PHP Oracle 8 module (available from PHP 3.0.5). It supports persistent connections, fetching rows into arrays, prepare/execute (variable binding) and has a new and improved error interface.
Categories : Databases, Oracle, PHP, Arrays, Variables
Simple class for accessing databases like MSSql Server, Oracle etc by Raju
Categories : PHP, MS SQL Server, Databases, PHP Classes, Oracle
normalize fields and strings used in where (command's Sql)
Categories : PHP, Databases, Oracle, Functions
Logs hits to any page which includes it. Automatically utilises page access information left behind by PHP/FI2.0.
Categories : Databases, PHP, mSQL, Databases
StoredProcedure, Stored Procedure, Oracle, OCI8, OCI8i
Categories : OCI8, Oracle, Databases, PHP
Installing Oracle support to PHP running in Apache
Categories : PHP Configuration, Apache, Oracle, Databases, Web Servers
PHP CLASS for ORACLE (database connectivity)
Categories : PHP, PHP Classes, Classes and Objects, Databases, Oracle
This program allows you to upload an ODBC ressource - i.e. an MS-Access database to a MySQL server.
Categories : Databases, MySQL, Complete Programs, PHP, Databases
Function for retrieving MySQL enum values into a PHP array.
Categories : PHP, Databases, MySQL, Arrays
Function Query2Array will read an PEAR-DB-Query-Result into an Array. You may specify a Column used as Array-Keys, and you may specify the Number of Rows to skip at the beginning and the Number to fetch (-1 = infinite).
Categories : Functions, PHP, Databases
An SQL Administration User Interface for the Web
Categories : Databases, PHP, mSQL, Complete Programs
A wrapper function to format dates coming from a databases with the same syntax as PHP's date() function.
Categories : Date Time, Databases, PHP
PHP and MySQL scripting for Muyltiple CheckBoxes
Categories : HTML and PHP, MySQL, Databases, PHP
Report Generation in Microsoft Access from a MYSQL database
Categories : PHP, MySQL, Databases, MS Access
 Enrico Faccin wrote : 321
You can limit the search on both side with this 
nested query:

SELECT * FROM (
    SELECT *, ROWNUM
        FROM mytable
        WHERE myconditions
) WHERE ROWNUM&gt;xx AND ROWNUM&lt;yy;
 
 Marcelo Toledo wrote : 614
If I do something like: select * from (select aaa, bbb, ROWNUM as X from table where aaa=bbb order by aaa desc) where X = 2;

If I want to get the second row returned this will not work as expected. Look why:
DATA_ENTRADA            ROWNUM
------------------- ----------
16/05/2001 12:57:08         32 &lt;- this is the firt row
16/05/2001 11:51:45         31 &lt;- second
15/05/2001 18:05:53         30
15/05/2001 18:04:47         29
15/05/2001 18:04:10         28

So, to get the real row number in this case you will have to make 3 selects. For example:

select * from (select a, ROWNUM as X from (select a from table where ... order by ...)) where X = 2;
 
 Marcelo Toledo wrote : 615
If I do something like: select * from (select aaa, bbb, ROWNUM as X from table where aaa=bbb order by aaa desc) where X = 2;

If I want to get the second row returned this will not work as expected. Look why:
DATA_ENTRADA            ROWNUM
------------------- ----------
16/05/2001 12:57:08         32 &lt;- this is the firt row
16/05/2001 11:51:45         31 &lt;- second
15/05/2001 18:05:53         30
15/05/2001 18:04:47         29
15/05/2001 18:04:10         28

So, to get the real row number in this case you will have to make 3 selects. For example:

select * from (select a, ROWNUM as X from (select a from table where ... order by ...)) where X = 2;
 
 Didier Berard wrote :1056
Hier is a full example for the limitation:

select * from (select a, b, c, rownum as limit from mytable where conditions order by whatiwant) where limit&gt;x and limit &lt;y;

with: whatiwant="a DES"C, x=3 and y=6
the result will be:

  A   B   C      LIMIT
--- --- --- ----------
 30   1   2          4
 29   2   2          5


Thanks to Enrico Faccin