Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> paged Cursor

paged Cursor

From: Rohrbacher, Ing. Boris <rohbo_at_sbox.tu-graz.ac.at>
Date: 1997/12/10
Message-ID: <348EFF44.9C64F063@sbox.tu-graz.ac.at>

This is a multi-part message in MIME format. --------------925CB0B80AE0006F8981207A
Content-Type: multipart/alternative; boundary="------------9F9846ACD827AE5896786D07"

--------------9F9846ACD827AE5896786D07
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Hi,

  I had, and will have the problem many times :

 I implemented to possible solutions, each of has advantages and disadvantages.

 solution 1 : Remember the SQL Statement ( for instance in an tmp table or for zero administration in the htmlpage itself   utilizing the whole page as a form and implementing the link as a form.submit in a simple javasrcipt.
  and run the sql Statement with dbms_sql.... Package if you happen to use a Oracle database.
  Give the query a query id e.g. a number ...  On the HTML page implement the link or whatever you are using to call the next page with appropriate
 parameters specifing the query id and the row where the page should start.

 How to come to the next page :
 Open then Cursor using dbms_sql or whatever tool you are using to fetch rows from database
 Primitivly fetch till you have reached the start of the desired page and start generating the page from this point.

 Advantages : Only sql statement is stored temporarilly.  Possibility to change the given statement from page to page. Most import ORDER BY as you please.
 More real data as in solution 2 because changed and updated rows are reflected from call to call.

 Disadvantages :
  1.) Empty fetching from from first result set row to starting point of
  page can degrade performance if you happen to have a very complex statement and/or where large result set.   My expiriences are that the biggest part of response time is not fetching data, but getting the potential result set for   a Query. I did some measurements on a large Oracle database and found out that most time spend is between
  opening a cursor and fetching the first row. Time from the first to the last row was often a small part of the time before.

  ==> slower response time than solution 2

 2.) Cursor needs to be executed each time. If you have a complex query this means very slow paging

 solution 2 : Store a unique key kombination for a single row of the result set in a tmp table, ( either one table for   each query, or single table, sorting out queries with a query id )   Tmp table needs to have a column for a generated sort value, filling it with the value of rownum of the original cursor.   In the HTML page define a appropriate link with the sort value as parameter for other pages
  How to come to the next page :
  Write programm that is called with sort value ( that is the number of the row in the result set ) were the page should start   ( lets name it page_start_sort_value ) and query id   Select alle rows from tmp table where sort value is between page_start_sort_value and page_start_sort_value + rows per page and all other information. e.g. for your example with emp :

   select ename, empno, sort_value from tmp, emp where tmp.sort_value between page_start_sort_value and ( page_start_sort_value + rows_per_page ) and tmp.empno = emp.empno

   order by sort value

 Advantages : Usually very fast pageing. Easy to handle.  Only ONE executioin of original query.

 Disadvantages : All results for each queries are stored. This can lead to enourmous tmp data depending on query traffic and content, but usually you can limit queries to a reasonable count of rows returned. E.g. in public library catalogs (OPAC ) result sets are often limited to a few hundred titels. Nobody likes to browse through 1000+ rows if he or she is looking for a single row. If a query returns more than 150 rows more than 75% of users start over with refined kriterias.

You can find an example of this kind of solution under UBTUG.BIS Opac V 1.1 - Eingabe

I hope I could give a advise.
Regards ,
  Boris i.e Robo.

--------------9F9846ACD827AE5896786D07
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<HTML>

Hi,

<P>&nbsp; I had, and will have the problem many times :
<BR>&nbsp;
<BR>&nbsp;I implemented to possible solutions,&nbsp;&nbsp; each of has
advantages and disadvantages.
<BR>&nbsp;
<BR>&nbsp;solution 1 :&nbsp;&nbsp; Remember the SQL Statement&nbsp; ( for
instance in an tmp table&nbsp; or&nbsp; for zero administration in the htmlpage itself
<BR>&nbsp; utilizing the whole page as a form and implementing the link
as a form.submit in a simple javasrcipt.
<BR>&nbsp; and run the sql Statement&nbsp; with&nbsp; dbms_sql....&nbsp;
Package&nbsp; if you happen to use a Oracle database.
<BR>&nbsp; Give&nbsp; the query&nbsp; a&nbsp; query id&nbsp; e.g. a number
...
<BR>&nbsp;On the HTML page&nbsp; implement&nbsp; the link or whatever you
are using to call the next page with appropriate
<BR>&nbsp;parameters specifing&nbsp; the query id&nbsp; and&nbsp; the row
where&nbsp; the page should start.
<BR>&nbsp;
<BR>&nbsp;How to come to the next page :
<BR>&nbsp;Open then Cursor using&nbsp; dbms_sql&nbsp;&nbsp; or whatever
tool you are using to fetch rows from database
<BR>&nbsp;Primitivly&nbsp; fetch&nbsp; till you have reached the start&nbsp;
of&nbsp; the desired page and start generating the page from this point.

<P>&nbsp;Advantages :&nbsp; Only sql statement is stored temporarilly.
<BR>&nbsp;Possibility to change the given statement&nbsp; from page to
page. Most import&nbsp; ORDER&nbsp; BY as you please.
<BR>&nbsp;More real data as in solution 2 because changed and updated rows
are reflected from call to call.

<P>&nbsp;Disadvantages :
<BR>&nbsp; 1.)&nbsp; Empty fetching from from first result set row to starting
point of
<BR>&nbsp; page&nbsp; can degrade&nbsp; performance if you happen to have
a very complex statement and/or where large result set.
<BR>&nbsp; My expiriences are that&nbsp; the biggest part of response&nbsp;
time&nbsp; is&nbsp; not fetching data, but&nbsp; getting the potential result set for
<BR>&nbsp; a Query.&nbsp; I did some measurements on a large Oracle database
and found out that&nbsp;&nbsp; most time spend is between
<BR>&nbsp; opening&nbsp; a cursor&nbsp;&nbsp; and fetching the first row.&nbsp;
Time from the first to the last row was often a small part of the time before.

<P>&nbsp; ==>&nbsp; slower response time than&nbsp; solution 2

<P>&nbsp;2.) Cursor needs to be executed each time. If you have a complex
query this means very&nbsp; slow paging
<BR>&nbsp;
<BR>&nbsp;solution 2 :&nbsp; Store a unique key kombination for a single
row of the result set in a tmp table,&nbsp; ( either one table for
<BR>&nbsp; each query, or single table, sorting out queries with&nbsp;
a query id )
<BR>&nbsp; Tmp table needs to have a column for a generated&nbsp; sort
value, filling it with the value of rownum of the original cursor.
<BR>&nbsp; In the HTML page define a appropriate link with the sort value
as parameter for other pages
<BR>&nbsp; How to come to the next page :
<BR>&nbsp; Write programm that is called with&nbsp; sort value ( that is
the number of the row in the result set ) were the page should start
<BR>&nbsp; ( lets name it page_start_sort_value ) and query id
<BR>&nbsp; Select alle&nbsp; rows from tmp table where&nbsp; sort value
is between page_start_sort_value and page_start_sort_value + rows&nbsp; per page&nbsp;&nbsp;&nbsp;&nbsp; and&nbsp; all other information. e.g. for your example with emp :

<P>&nbsp;&nbsp; select&nbsp; ename, empno, sort_value&nbsp; from&nbsp;&nbsp;
tmp, emp&nbsp; where&nbsp; tmp.sort_value between page_start_sort_value and ( page_start_sort_value + rows_per_page )&nbsp;&nbsp; and&nbsp; tmp.empno = emp.empno
<BR>&nbsp;&nbsp; order by sort value
<BR>&nbsp;

<P>&nbsp;Advantages : Usually very fast&nbsp; pageing.&nbsp; Easy to handle.
<BR>&nbsp;Only ONE executioin of original query.

<P>&nbsp;Disadvantages :&nbsp; All results for each queries are stored.
This can lead to enourmous tmp data depending on query traffic and content, but usually you can limit queries to a reasonable&nbsp; count of rows&nbsp; returned.&nbsp; E.g. in public library catalogs (OPAC ) result
<BR>sets are often&nbsp; limited to a few hundred titels.&nbsp; Nobody
likes to browse through 1000+&nbsp; rows if he or she is looking for a single row.
<BR>If a query returns more than 150 rows&nbsp; more than 75% of users&nbsp;
start over with refined kriterias.

<P>You can find an example of this kind&nbsp; of solution under&nbsp; <A HREF="http://cisc.tu-graz.ac.at:8000/rb/owa/opac.eingabe_v1">UBTUG.BIS
Opac V 1.1 - Eingabe</A>

<P>I hope I could give a advise.
<BR>Regards ,
<BR>&nbsp; Boris&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; i.e&nbsp; Robo.</HTML>

--------------9F9846ACD827AE5896786D07--

--------------925CB0B80AE0006F8981207A
Content-Type: text/x-vcard; charset=us-ascii; name="vcard.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Boris Rohrbacher
Content-Disposition: attachment; filename="vcard.vcf"

begin:          vcard
fn:             Boris Rohrbacher
n:              Rohrbacher;Boris
org:            Zentraler Informatikdienst der Technischen Universität Graz 
adr:            Steyrergasse 30 ;;oder Griesplatz 36/1;GRAZ;Styria;A-8027;Austria
email;internet: rohbo_at_sbox.tu-graz.ac.at
title:          freier Mitarbeiter 
tel;work:       +43-316-873-6391
tel;fax:        +43-316-873-7766
tel;home:       +43-316-971221

x-mozilla-cpt: ;0
x-mozilla-html: FALSE
version:        2.1
end:            vcard


--------------925CB0B80AE0006F8981207A-- Received on Wed Dec 10 1997 - 00:00:00 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US