Select a specific number of rows in query
How can a specific number of rows be selected in a query? For example, a query retrieves 30,000 records and I want to retrieve the output by groups of 5,000. I want the query to retrieve the first 5,000 records, then the next 5,000 records etc. I tried rownum but that does not work.
Thanks,
PANY
Not AGAIN. Please...........
Do you know how to Google? Search forum?
Why do you ask this boring FAQ AGAIN?
Sybrand Bakker
Senior Oracle DBA
Experts: Those who know how to search.
Similar Messages
-
Getting a specific number of rows
Hi,
I would like to know how to get a specific number of rows. For example, I want to page data in my web application, so I'd like to be able to retrieve just 25 rows in my SELECT statement. I searched and I couldn't see anything under the obvious keywords of LIMIT and TOP (as used by other database vendors) so I'm wondering if possible, what do I need to do - a pointer to the relevant documentation would be helpful also.You can achieve this with rownum
http://download-uk.oracle.com/docs/cd/B19306_01/server.102/b14200/pseudocolumns009.htm#i1006297
Best regards
Maxim -
Fitching a specific number of rows
hi all
i want to fitch a specific number of rows in my query
not all matches (SQL2000 Server )
what command in my sql query can be placed to do so
thanksset rowcount n
-
Select specific number of rows
i'm listing all data entries in a database.
for that i want to select the 1st ten entires, then the next ten and so on ordered
by date_column.
how can i do that? is it possible with rownum?
in mysql/php i did it with limit
$query = "select * from article where parent_id=0 order by date desc, time desc limit $select, 10";
please email me.
thanks for help
chrisbut what about rownum if i want the
records from 10-20?
<BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by Chen Zhao ([email protected]):
If you are using Oracle 8i, you can use ROWNUM to specify the specific number of records. You can see the ROWNUM by querying:
SELECT *
FROM (SELECT column_name FROM table_name ORDER BY column_name)
WHERE ROWNUM<10
CHEN<HR></BLOCKQUOTE>
null -
Return specific number of rows depending on the data in a column in table
Hi,
I have a table named orders which has column orderid and noofbookstoorder in addition to other columns.
I want to query the orders table and depending on the value of the 'noofbookstoorder' value return that number of rows.
Eg
Orderid noofbookstoorder
1 1
2 3
3 2
when I query the above data saying
select * from orders where orderid=2;
since it has noofbookstoorders value as 3 the query should return 3 rows and when I query
select * from orders where orderid=3;
it should return 2 rows and
select * from orders where orderid=1;
should return 1 row.
Is it possible to achieve this. If yes, then how do I write my query.
Thanks in advance.with t as (
select 1 Orderid,1 noofbookstoorder from dual union all
select 2,3 from dual union all
select 3,2 from dual
select t.*
from t,
table(cast(multiset(select 1 from dual connect by level <= noofbookstoorder) as sys.OdciNumberList))
where Orderid = <order-id>
/For example:
SQL> with t as (
2 select 1 Orderid,1 noofbookstoorder from dual union all
3 select 2,3 from dual union all
4 select 3,2 from dual
5 )
6 select t.*
7 from t,
8 table(cast(multiset(select 1 from dual connect by level <= noofbookstoorder) as sys.OdciNumberList))
9 where Orderid = 2
10 /
ORDERID NOOFBOOKSTOORDER
2 3
2 3
2 3
SQL> with t as (
2 select 1 Orderid,1 noofbookstoorder from dual union all
3 select 2,3 from dual union all
4 select 3,2 from dual
5 )
6 select t.*
7 from t,
8 table(cast(multiset(select 1 from dual connect by level <= noofbookstoorder) as sys.OdciNumberList))
9 where Orderid = 3
10 /
ORDERID NOOFBOOKSTOORDER
3 2
3 2
SQL> with t as (
2 select 1 Orderid,1 noofbookstoorder from dual union all
3 select 2,3 from dual union all
4 select 3,2 from dual
5 )
6 select t.*
7 from t,
8 table(cast(multiset(select 1 from dual connect by level <= noofbookstoorder) as sys.Odc
iNumberList))
9 where Orderid = 1
10 /
ORDERID NOOFBOOKSTOORDER
1 1
SQL> -- And if you want to select multiple orders
SQL> with t as (
2 select 1 Orderid,1 noofbookstoorder from dual union all
3 select 2,3 from dual union all
4 select 3,2 from dual
5 )
6 select t.*
7 from t,
8 table(cast(multiset(select 1 from dual connect by level <= noofbookstoorder) as sys.Odc
iNumberList))
9 where Orderid in (2,3)
10 /
ORDERID NOOFBOOKSTOORDER
2 3
2 3
2 3
3 2
3 2
SQL> SY.
Edited by: Solomon Yakobson on Oct 26, 2009 7:36 AM -
Regarding total number of rows in query analyzer
Dear all,
I have one query. when i execute the query using analyzer i get upto 65000 rows only in excel file. We have 2007 excel format and it has row-capacity more than that.
From report i should get around 80000 rows. Is there any setting to extend the no. of rows, so that i can get complete report?
i can give some restriction on query, but that is another option.
Plz guide me for the same.
Regards,
Omkar
Edited by: omkar patil on Jul 23, 2008 12:09 PMQuery JumpTargets are nothing but going one query to 1.another Query,
2. Any Transaction Code( screen) at cube level OR ODS level.
Clearly I am specifing that If u wnt to diplay Detailed data( ODS data) for respect Record at the cube level we will use this QueryJump Tagets .
It is also called as Report to Report Interface.
Example scenario:
On Cube level query Diplaying Different vendor balances but it is not diplaying the document details for the balances for that perticuler vendor .
so at this situation u have to create Interface between Cube query with Vendor details & ODS query with document Details of that perticuler vendor.
How to do This : steps to do this:
1.Goto Transaction code RSBBS.
2.There ur having two tabsrips 1.Query 2.Infocube
3.click on query tabstrip it will ask query name ---> enter the query name ( Base query Which u created on Cube vendor details)
4.click on create button it will give some some screen in that select REPORT TYPE as BW Bex Query radio button-->select Traget system Local-->at Report u have to enter ur Detailed report which u created on ODS.
5. Click on Transfer (f8)
6.Save it.
How to check query jump:
1. Execuite ur base Query ( Query which is created on ur cube )
2.click on any( vendor) column of that report -
>right click->select goto-> there u will see the query name which u created on ODS ->click on it
It will dispaly the detail report for that (vendor) column. -
Selecting a small number of rows
Hello,
I am looking for something in PL/SQL that will allow me to return a limited number of rows. In other SQL's this might be something like:
set row count=100
select * from tab1 --- returns first 100 rows foundSQL> select * from emp;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7566 JONES MANAGER 7839 02-APR-81 2975 1000 20
7902 FORD ANALYST 7566 03-DEC-81 3000 20
7839 KING PRESIDENT 17-NOV-81 5000 10
7698 BLAKE MANAGER 7839 01-MAY-81 2850 30
7782 CLARK MANAGER 7839 09-JUN-81 2450 10
7369 SMITH CLERK 7902 17-DEC-80 800 20
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
7788 SCOTT ANALYST 7566 09-DEC-82 3000 20
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30
7876 ADAMS CLERK 7788 12-JAN-83 1100 20
7900 JAMES CLERK 7698 03-DEC-81 950 30
7934 MILLER CLERK 7782 23-JAN-82 1300 10
14 rows selected.
SQL> select e.empno, e.ename, e.job, e.hiredate
2 from (select rownum rn, empno, ename, job, hiredate
3 from emp) e
4 where e.rn <= 10;
EMPNO ENAME JOB HIREDATE
7566 JONES MANAGER 02-APR-81
7902 FORD ANALYST 03-DEC-81
7839 KING PRESIDENT 17-NOV-81
7698 BLAKE MANAGER 01-MAY-81
7782 CLARK MANAGER 09-JUN-81
7369 SMITH CLERK 17-DEC-80
7499 ALLEN SALESMAN 20-FEB-81
7521 WARD SALESMAN 22-FEB-81
7654 MARTIN SALESMAN 28-SEP-81
7788 SCOTT ANALYST 09-DEC-82
10 rows selected.
SQL> -
Dynamic Select with different number of rows
Hi all,
I have a procedure who receives a table name and array of column names of that table.
I need to create a specific select statement with this parameters. Of course, this could change because the number of column names may differ from each invocation the this procedure.
Here's my procedure:
PROCEDURE column_scramble (pv_table_name
VARCHAR2,
ptbl_col_names
tbl_col_names)
IS
lv_query
VARCHAR2 (32000);
cur_handle INTEGER;
temp
NUMBER;
BEGIN
IF ptbl_col_names.COUNT > 0
THEN
lv_query := 'SELECT old.id, ';
FOR i IN ptbl_col_names.FIRST .. ptbl_col_names.LAST
LOOP
lv_query :=
lv_query
|| 'new.'
|| ptbl_col_names
|| ' as new_'
|| ptbl_col_names (i);
IF i < ptbl_col_names.LAST
THEN
lv_query := lv_query || ',';
END IF;
END LOOP;
lv_query :=
lv_query
|| ' FROM ( SELECT ROWNUM rr, '
|| pv_table_name
|| '.* FROM '
|| pv_table_name
|| ' ORDER BY '
|| pv_table_name
|| '.id) old, (SELECT ROWNUM rr, a.* FROM ( SELECT id,';
FOR j IN ptbl_col_names.FIRST .. ptbl_col_names.LAST
LOOP
lv_query := lv_query || ptbl_col_names (j);
IF j < ptbl_col_names.LAST
THEN
lv_query := lv_query || ',';
END IF;
END LOOP;
lv_query :=
lv_query
|| ' FROM '
|| pv_table_name
|| ' ORDER BY DBMS_RANDOM.VALUE) a) new WHERE old.rr = new.rr';
END IF;
DBMS_OUTPUT.put_line ('LV_QUERY: ' || lv_query);
cur_handle := DBMS_SQL.open_cursor;
DBMS_SQL.parse (cur_handle, lv_query, DBMS_SQL.native);
temp := DBMS_SQL.execute (cur_handle);
LOOP
IF DBMS_SQL.fetch_rows (cur_handle) = 0
THEN
EXIT;
ELSE
lv_query := 'UPDATE ' || pv_table_name || 'SET ';
FOR s IN 1 .. ptbl_col_names.COUNT
LOOP
lv_query :=
lv_query
|| ptbl_col_names (s)
|| '='
|| <return_value(s)>;
IF s < ptbl_col_names.COUNT
THEN
lv_query := lv_query || ',';
END IF;
END LOOP;
lv_query := lv_query || ' WHERE id = ' || <return_value_id>;
END IF;
END LOOP;
DBMS_SQL.close_cursor (cur_handle);
END column_scramble;
Thanks in advance,
FilipeAvoid using the "cumbersome" DBMS_SQL, try this:
CREATE OR REPLACE TYPE tbl_col_names IS VARRAY (100) OF VARCHAR2 (40);
CREATE OR REPLACE PROCEDURE column_scramble
( pv_table_name VARCHAR2, ptbl_col_names tbl_col_names
, pmy_cursor OUT SYS_REFCURSOR) --<<< NOTE: I added this parameter
IS
lv_query VARCHAR2 (32000);
cur_handle INTEGER;
temp NUMBER;
BEGIN
IF ptbl_col_names.COUNT > 0
THEN
lv_query := 'SELECT old.id, ';
FOR i IN ptbl_col_names.FIRST .. ptbl_col_names.LAST
LOOP
lv_query := lv_query || 'new.' || ptbl_col_names ( i)
|| ' as new_' || ptbl_col_names ( i);
IF i < ptbl_col_names.LAST
THEN
lv_query := lv_query || ',';
END IF;
END LOOP;
lv_query := lv_query ||
' FROM ( SELECT ROWNUM rr, ' || pv_table_name ||
'.* FROM ' || pv_table_name ||
' ORDER BY ' || pv_table_name ||'.id) old
, (SELECT ROWNUM rr, a.* FROM ( SELECT id,';
FOR j IN ptbl_col_names.FIRST .. ptbl_col_names.LAST
LOOP
lv_query := lv_query || ptbl_col_names ( j);
IF j < ptbl_col_names.LAST
THEN
lv_query := lv_query || ',';
END IF;
END LOOP;
lv_query := lv_query || ' FROM ' || pv_table_name ||
' ORDER BY DBMS_RANDOM.VALUE) a) new WHERE old.rr = new.rr';
END IF;
DBMS_OUTPUT.put_line ( 'LV_QUERY: ' || lv_query);
OPEN pmy_cursor FOR lv_query;
END;
-- And to execute do this:
VAR my_cursor REFCURSOR;
DECLARE
emp_col tbl_col_names;
BEGIN
emp_col :=
tbl_col_names (
'DEPTNO'
, 'MGR'
, 'EMPNO'
, 'ENAME'
column_scramble ( 'EMP3', emp_col, :my_cursor);
END;
PRINT my_cursor;
PL/SQL procedure successfully completed.
ID NEW_DEPTNO NEW_MGR NEW_EMPNO NEW_ENAME
1 10 7839 KING
2 20 7566 7788 TIGER
3 30 7698 7499 ALLEN
4 10 7839 7782 CLARK
5 20 7566 7502 TIGER
6 30 7698 7654 MARTIN
7 30 7839 7698 BLAKE
8 20 7839 7566 JONES
9 20 7566 7788 SCOTT
10 20 7788 7876 ADAMS
11 30 7698 7521 WARD
12 20 7902 7369 SMITH
13 30 7698 7844 TURNER
14 30 7698 7501 BRWN
14 rows selected. -
Specific number of rows within field(s)
I'd like to get Top-N of Amt within Name&Loc as shown below.
Is there a way to reset either COUNT or ROWNUM to get this result?
Name---Loc--(ROWNUM)--Amt
James--abc--------1--1000
James--abc--------2---900
James--abc--------3---750
James--def--------1---500
James--def--------2---300
Jill---abc--------1---400
Jill---abc--------2---150
Jack---xyz--------1--2000
Jack---xyz--------2--1800
Thank you in advance for your help.try this,
select rownum as rank,ename,sal from ( select ename,sal from emp order by sal desc) where rownum<6
This query works on EMP table of SCOTT user.
If you change "desc" to "asc" it will start from lower to higher values. You can also play with the condition ( rownum < 6 ) to fetch ur desired no. of rows.
Hope this helps,
Kalpen.
<BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by Danielle:
Thanks for the reply, but that's not what I'm looking for.
Is there a way to get the Top-N (top 10,top20...)records within a group of fields (e.g. Name & Loc )?<HR></BLOCKQUOTE>
null -
Getting a specified number of rows froma query
How can I get the minimum 3 row from a query after a order by in the select
Eg;
SELECT ROWNUM,ROWID, connection_id, GROUP_ID
FROM prov_pending_commands
ORDER BY group_id
4 AAAZWTAAYAAANMiAAA 680932 32702947
3 AAAZWTAAYAAANMgAAB 644610 32703643
2 AAAZWTAAYAAANLrAAB 51925942 32704602
1 AAAZWTAAYAAANLrAAA 61247803 32704613
I need to get only the group ids 32702947,32703643, 32704602 for some other processing.
I checked by getting rownum or row id, but after ordering it gives wrong data
Please need helpHi,
Try this,
select * from (select name, row_number() over (order by name) as row_num from test) row_num
where row_num <= 3
If you are looking for something else explain us more with sample output.
Thanks!
M T -
How to find number of rows after query
I have a simple query page. On this page I enter query criteria and hit the go button I get the query result. (say it finds one record)
On processFormRequest of the controler of this page after I execute (executing explicitly because I am using some bind variable too) the query I print getFetchedRowCount() and getRowCount() and I get 10 (as the total records according bind variable criteria are 10). Where I am expecting 1 as the result.
and I want to get the value of that row as well.
Can anyone please guide me how I can achieve this?
ThanksYes I am using queryBean for search region. I can see both, criteria that I am passing through search region and bind variable in the query.
If I pass the customer name it gives me that customer as a result.
but the counts i get doesn't seem to consider that search criteria from query region.
Interestingly when I execute the query again with the same customer name ...I get the correct count. i.e 1
Followoing is the query from "about this page-->business component reference details."
SELECT * FROM
select distinct super_customers.party_name
customer_name,
super_cust.cust_account_id customer_id,
sup_cust_acct.Status,
sup_cust_acct.customer_class_code,
CINT_CRM.Get_Customer_Type(sup_cust_acct.customer_type),
sup_cust_acct.FOB_Point,
sup_cust_acct.sales_channel_code,
From
hz_parties Customers,
hz_parties Super_Customers,
hz_parties cust_cont_rel,
HZ_RELATIONSHIPS REL,
HZ_Cust_Accounts rel_cust_acct,
HZ_Cust_Accounts sup_cust_acct,
HZ_CUST_ACCT_RELATE_ALL Super_Cust
where
customers.party_id = rel.subject_id
and cust_cont_rel.party_id = rel.party_id
and rel_cust_acct.party_id = customers.party_id
and Super_Cust.related_cust_account_id = rel_cust_Acct.cust_account_id
and super_cust.cust_account_id = sup_cust_acct.cust_account_id
and Super_Customers.party_id = sup_cust_acct.party_id
and sup_cust_acct.account_number like 'SC%'
and cust_cont_rel.status = 'A'
and rel.status = 'A'
and rel_cust_acct.status = 'A'
and Super_Cust.status = 'A'
and sup_cust_acct.account_number like nvl(:customerNumber, sup_cust_acct.account_number)
and nvl(rel.object_id, -1) = nvl(nvl(:contactPartyId, rel.object_id), -1)
and upper(super_customers.party_name) like upper(nvl(:customerName, super_customers.party_name))
and sup_cust_acct.account_number like 'SC%') QRSLT
WHERE
(( UPPER(CUSTOMER_NAME) like UPPER(:5)
AND (CUSTOMER_NAME like :6
OR CUSTOMER_NAME like :7
OR CUSTOMER_NAME like :8
OR CUSTOMER_NAME like :9)) -
Selecting only required number of rows in an external table
Hi,
I have an external table with many flat files as source.. I know I can skip rows using the keyword 'SKIP'. I want to select only first 'n' rows from all the flat files as the rows available in my oracle external table. Is this Possible?...
eg..
Flat file 1
c1,c2
123,45
132,56
'ahgh',34
'dfd',22
Flat file 2
c1,c2
56,1212
545,45
'ahcsd',4
'dds',24
I want to create a file which contains the rows, means only the 2nd and 3rd rows from each flat files
123,45
132,56
56,1212
545,45
Thanks in Advance
PouloseIf this means selecting from all these flat files at the same time then it might get a bit cumbersome. Basically you will have to create an external table for each flat file and then do something like this:
SELECT * FROM
( select c1, c2 from
( select c1, c2, rownum as rn from ext_table_1 )
where rn in (2, 3)
union all
select c1, c2 from
( select c1, c2, rownum as rn from ext_table_2 )
where rn in (2, 3)
union all
select c1, c2 from
( select c1, c2, rownum as rn from ext_table_3 )
where rn in (2, 3)
union all
/Cheers, APC -
Setting a specific number of rows visiable in a JTable
Hi there,
I am implementing the Master-Detail pattern by using a using a JSplitPane to devide a JPanel into two.
In the upper split-pane I show a JTable as the Master View.
In the lower split-pane I show a JTable as the Detail View.
My problem is that I just want to show 2 (two) rows and the Header in the Detail-View.
The default behavier is that my SplitPane shows 1 and a half row and the tableHeader.
How can I tell the SplitPane that I (only) want two rows and the Header ?table.setPreferredSize(...);Hi again,
thanks for input !
I tried your suggestion but it did not help me.
int rowHeight = detailCompareTable.getRowHeight();
Dimension headerSize = detailCompareTable.getTableHeader().getPreferredSize();
d = new Dimension ((int) d.getWidth(), (int) (2 * rowHeight + headerSize.getHeight()));
detailCompareTable.setPreferredSize(d);
masterDetailSplitPane.resetToPreferredSizes();What am I gettig wrong ? -
How to control the number of rows selected from a sybase database table?
Hi, JDBC guru,
I'm working on project using Sybase 11.9.x database.We need to process a record in a table,first select it from the table,then do some computing,finally write it to a dbf file, if the above steps succeed,remove the original row in the table.Quite evidently, all these operation should be put into one transaction. But how can I select just a number of rows from the sybase database table?
Any hints?
Thank you in advance.
Regards,
JusitneStatement stmt...
stmt.setMaxRows(20); -
Limit Number for Rows in BW Query Result
Hello Experts,
I am creating a query to be consumed by a web service. Therefore, I want to restrict the number of rows the query can display. Does anyone know a way to limit the result set to display only say FIRST 100 rows of data?
I have looked at 'safety belt' solution, i.e. limiting number of cells to for example, 5000 cells. However, when the limit is exceeded the query just shows an error message not the first 5000 cells.
thanks,
KartikHi,
You can do some things like..........
Do not display the data in a detailed level.
Use Always Suppress option in the result set.
Also it depends on your Query definition. If your rows contains Branch wise or Region Wise, then your report will be fit in your first level of output. You need not to drilldown further.
Why do you want to consider only first 1000 rows if you are planning to use it by Web service?
I don't know whether it is feasible or not. I have one more alternative for you. You can try to achieve by APD by the Query. Insert a ABAP routine which should consider first 1000 result rows for your Web service. Just throw a light on this idea..............
Regards,
Suman
Maybe you are looking for
-
Can I set a default Reply-From email address on my iPad/iPhone?
In Mail for the Mac, there is an option under the Compose settings to set a default Reply-From email address for all your emails, so that, regardless of which account any email came from, you will always reply by default from one specific address. Is
-
OS X 10.6.8 keeps freezing on my 2008 Macbook Pro
I recently upgraded to OS X Snow Leopard and every now and then, maybe up to twice a day, my macbook pro freezes. While using the computer regulary for anything, at randomly the entire screen will blink and freeze at whatever I was on, and only the m
-
OOPS concept not included in java
Could anyone help me which " OOPS concept " is not included in Java thanks Dilip
-
MDS_LOAD_COCKPIT error
Hello All, We are in SRM 7.0 one client sceanrio on ECC 6.0. When manually replicating new products created in ECC to SRM using the transaction MDS_LOAD_COCKPIT, I am getting an error " Assign a base category". I was able to replicate all the existin
-
D110 prints cover page when lphotos are sent
How do I stop my D110 from printing the email address on the first sheet of lphoto paper prior to printing the photo. Photo sent from BB Curve using gmail.