This script can be used to return a range of rows from the database. Back to SQL scripts


SELECT b.*
FROM
(SELECT rownum rnum, emp.*
FROM emp) b
WHERE b.rnum between &initial and &final;



To run the code, cut and paste it onto your favourite editor and save the file. When you run it through SQL*PLUS, it asks you to specify the range of the rows you want to see. So for example if you want to display all rows between the 2nd and the 6th row, both inclusive, enter the value 2 for &initial and 6 for &final, when prompted.

When used with the emp table, as in the example, you get the following output.

SQL> SELECT *
FROM
(SELECT rownum rnum, emp.*
FROM emp) b
WHERE b.rnum between &initial and &final;
Enter value for initial: 2
Enter value for final: 5
old 5: WHERE b.rnum between &initial and &final
new 5: WHERE b.rnum between 2 and 5

RNUMEMPNOENAMEJOBMGRHIREDATESALCOMMDEPTNO
----------------------------------------------------------------------------------
27499ALLENSALESMAN769820-FEB-81160030030
37521WARDSALESMAN769822-FEB-81125050030
47566JONESMANAGER783902-APR-81297520
57654MARTINSALESMAN769828-SEP-811250140030

SQL>


Back to SQL scripts
Hosted by www.Geocities.ws

1