Count the number of rows resulting from a select statement
Hi,
Is there any way of counting the number of rows resulting from a select statement. i.e I have a select distinct statement and I then want to perform an IF statement on the number of rows resulting from the select statement.
Any help appreciated
Thanks
Gary
Declare
var1 number;
Begin
select count(distinct column_name) into
var1 from table_name;
If var1 > x Then
End IF;
End;
Hope I understood the problem correctly
null
Similar Messages
-
How can I limit the number of rows returned by a select stat
How can I limit the number of rows returned by a select
statement. I have a query where I return the number of stores
that are located in a given area.. I only want to return the
first twenty-five stores. In some instances there may be over
200 stores in a given location.
I know is SQL 7 that I can set the pagesize to be 25....
Anything similiar in Oracle 8i?
nullDebbie (guest) wrote:
: Chad Nale (guest) wrote:
: : How can I limit the number of rows returned by a select
: : statement. I have a query where I return the number of
: stores
: : that are located in a given area.. I only want to return the
: : first twenty-five stores. In some instances there may be
: over
: : 200 stores in a given location.
: : I know is SQL 7 that I can set the pagesize to be 25....
: : Anything similiar in Oracle 8i?
: If you are in Sql*Plus, you could add the statement
: WHERE rownum <= 25
: Used together with an appropriate ORDER BY you
: could get the first 25 stores.
Watch out. ROWNUM is run before ORDER BY so this would only
order the 25 selected
null -
Can I limit the number of rows returned on a Select?
Can I limit the number of rows returned on a Select statement? I would be using JDBC in a Java program.
Use Java prepared statements with the equivalent of this SQL*plus script:
VARIABLE n number
EXEC :n := 3;
SELECT rownum FROM all_objects WHERE rownum <= :n;
ROWNUM
1
2
3
EXEC :n := 5;
SELECT rownum FROM all_objects WHERE rownum <= :n;
ROWNUM
1
2
3
4
5 -
How to count the number of rows in a resultser object?
hi there
how to count the number of rows in a resultser object which may contains millions of rows? besides using a while loop? thanksYou don't, you execute a query whose result is the record count of those records that match the search and then you execute the actual query to create your record set. Typically you do
select count(id) from YourTable where [filter]
from the resulting ResultSet do
int res.getInt(1);
which gives you the count and then
select id from YourTable where [filter]
to produce the actual result set.
in the second query the id part can be substituted with the actual fields you want. -
Count the number of rows inserted
Hi,
Is there a way to count the number of rows processed post DML in PL/SQL?
For eg,
BEGIN
INSERT INTO TMP1
SELECT * FROM EMP;
a function to count the number of rows inserted into tmp1SQL> set serveroutput on;
SQL> begin
2 insert into tmp1 select * from emp;
3 dbms_output.put_line(SQL%ROWCOUNT||' rows inserted');
4 end;
5 /
15 rows inserted
PL/SQL procedure successfully completed. -
How to count the number of Rows to be Updated before Update takes place..
Hi all,
I have a requirement, where i have to count the number of rows to be updated before updating it. SQL%ROWCOUNT gives the no. of rows updated ( after update takes place). How do i get to know the count of no. of rows to be updated/inserted/ deleted. I was looking for a simple solution, as above SQL%Rowcount. But i couldn't find any. I can use a Function and Return the value which will give me number of rows to be updated, But is there any Simple Logic other than this.. or any count function. Your Help is Appreciated. Thanks!If you really want to do this (I have no clue why you would need it), then you can piggy back on any existing pessimistic locking you may already have in place.
However, it would require two loops through the records of which you want to know the count before you update, and a second pass to update them.
I would really re-think the need for this, though.
SQL> create table t0304(c number);
Table created.
SQL> insert into t0304 select rownum from all_objects where rownum <= 10;
10 rows created.
SQL> commit;
Commit complete.
SQL> select * from t0304;
C
1
2
3
4
5
6
7
8
9
10
10 rows selected.
SQL> declare
2 cursor mycursor is select * from t0304 where mod(c,2) = 0 for update;
3 i number := 0;
4 begin
5 for r in mycursor loop
6 i := i + 1;
7 end loop;
8 dbms_output.put_line(i);
9 for r in mycursor loop
10 update t0304 set c = c + 20 where current of mycursor;
11 end loop;
12 end;
13 /
5
PL/SQL procedure successfully completed.
SQL> commit;
Commit complete.
SQL> select * from t0304;
C
1
22
3
24
5
26
7
28
9
30
10 rows selected.
SQL>Edited by: Steve Howard on Mar 4, 2011 5:57 PM -
How to count the number of rows in a cube!!??
Experts,
I can somebody tell me how do I count the number of rows in my cube when i am using listcube???..
Thanks
AshwinHi,
have a look ath this theard too
Number of Records in Cube
regards -
Count the Number of Rows in Data form
Hi,
I want to count the number of rows in a data form.In my form there is a large number of rows.Is there any way to count it.
Thanks.If you are on 11.1.2.x then you could look at adding a formula and using the CountA function - http://download.oracle.com/docs/cd/E17236_01/epm.1112/hp_admin/apcs03s06.html
Otherwise it would be possible using custom javascript which you would have to had some experience in using.
Cheers
John
http://john-goodwin.blogspot.com/ -
Count the number of rows in a workbook.
Hi Experts , I have a requirement to count the number of rows in a WorkBook.Will it be possible to do this by creating a KeyFigure?Or are there any options in BEx to count and display the number of Rows.Many thanks for all your help.
Hi
In the query create a calculated key figure called 'Count' and put a formula as =1, then use this count where ever applicable..you can very well count the no. of rec.
with this.
Hope this helps..
assign points if useful..
Cheers,
Pattan. -
How do you limit the number of rows return from query?
How do you limit the number of rows return from query? Do all databases support this kind of feature?
i think the standard is limit
to get the top 30
select * from mytable LIMIT 30;returns the first 30 rows
also if you want a range
select * from mytable LIMIT 10,30;returns 30 rows starting from 10
this last one is useful for displaying ranges... something similar happens in these forums when viewing topics and messages -
How to count the number or rows in file
Hi Experts,
I am file as source and Oracle as target. My file containing the some data which is going to load to the target.
My requirement is that I want to count the number of rows which my file contains. Please help me how to count the total number of rows in file.
Thx,
Sahadeva.Hi,
You won't give a name DEST_USER_NAME:ODI will get these information.
it is important Command on source and Command on Source side .
-Pls write jython code on Command on Source side
-And Command On Target side Choose technology as Oracle and set logical schema to HR_logical
Sorry my mistake.İt is related jython syntax.Here is code:
import java.lang as lang
import java.sql as sql
import java.lang.String
import os
lang.Class.forName("<%=snpRef.getInfo("DEST_JAVA_DRIVER")%>")
cons=sql.DriverManager.getConnection("<%=snpRef.getInfo("DEST_JAVA_URL")%>", "<%=snpRef.getInfo("DEST_USER_NAME")%>", "<%=snpRef.getInfo("DEST_PASS")%>")
dblinks= cons.createStatement()
file1=open('EMP.txt','r')
count=0
line=file1.readline()
while line !='':
count+=1
line=file1.readline()
file1.close()
sqlQuery = "insert into HR.ETL_FILE_LOG (FILE_COUNT) values (count)"
rqQuery= dblinks.execute(sqlDBLink)
cons.close()
Regards -
Can I "count" the number of rows excluding the header and footers
I have some tables that consist of a different number of rows, as the number is part of an equation I need to know the number of rows excluding the header and footers. I have the work around in =ROWS(ColumnG)-3, but is there a tidier way? I want to be able to add footers (or headers) too and not have these counted.
Many thanks
LeeHi Lee,
Add a column to your table (for purposes of this discussion, the new column is placed before column C, and becomes the new column C). enter the formula below in all regular cells, but NOT in header or footer cells:
=1
Use the formula below, placed anywhere (except in a regular cell in column C) to get the number of non-header, non-footer cells:
=COUNT($C)
The first formula will automatically be placed in cells added to column C, and the results will change to reflect the added rows.
Regards,
Barry -
Count the number of rows in an array
Hi there,
I'm quite new with Labview, maybe somebody can help me.
I have a .vi that controls two pump with certain ratios (to make a composition gradient). I export the data to an ascii file, which write the displacement of the two pumps in 2 colums. However, the number of rows is related to the ms-counter, and thus related to the processor of the computer. Now I need, at the end of the vi, to get the number of rows written to the ascii file, to do some further calculations. Does anybody know how to do this?!
ThanksYou could wire the loop-counter to a variable outside the loop, so you can see the number of iterations (don't forget to add 1).
You also can use the Array Size-Function. Here you get different outputs, according to the dimensions of the array to get the size of.
Here you can see what you get if you use this function:
1D-Array: one value
2D-Array: array, item 0 = number of rows, item 1 = number of columns
3D-Array: array, item 0 = number of pages, item 1 = number of rows, item 2 = number of columns
So if (in your case) you wire a 2D-Array you can use the array-size function, select item 0 of the array you get and you get the number of rows.
You can also have a look at the attachement.
Hope it helps.
Thomas
Using LV8.0
Don't be afraid to rate a good answer...
Attachments:
ArraySize.vi 17 KB -
Want to count the number of rows of analysis item in WAD Template
HI all,
Detail Description:
In my WAD report, i have a Export to Excel Option. But I want when I click on this button, one pop up will come only if no of rows of the Analysis Item is Greater than 10,000 ask for Do you want to proceed or not.
Means 1st i want to count the no of rows in the Analysis Item, after that it will check, if the no of rows is greater that 10,000. then the pop up will come.
Question:
Does anyone know, "how to count the no of rows of the analysis Item ?" . It will be better if you know you to implement this with the help of java script.
Means there must be some varible, which counts the no of rows. If you know then please help meHi,
Please find the below link which helps you to get solution of your question.
http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/d0bbb20f-2d7e-2e10-258f-8655daa41fab?QuickLink=index&overridelayout=true
It is mainly used to automate queries, web templates, and reports in different output formats like PDF, Excel,
XML, XHTML, and HTML
How to see WAD reports on browser:
The BEx Web Application Designer is a desktop application for creating Web applications with BW-specific contents. Using the BEx Web Application Designer, you can create an HTML page that contains contents such as various tables, charts or maps. This HTML page (Web application) provides the basis for not only Web applications with complex interaction, but also for Web cockpits and iViews.
http://help.sap.com/saphelp_nw04/helpdata/en/1a/456a3badc1b315e10000000a114084/content.htm
Web Application Designer for Beginners
https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/749a4622-0a01-0010-36bf-b6b30a2a3a22
Web Application Solutions: A Designer's Guide
http://www.lukew.com/resources/webapplicationsolutions.pdf
http://sap.ittoolbox.com/groups/technical-functional/sap-solution-manager/bw-web-application-designer-1955944
Feautures of WAD in 7.0
http://help.sap.com/saphelp_nw70/helpdata/en/88/4d354277dcb26be10000000a155106/frameset.htm
https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/5c46376d-0601-0010-83bf-c4f5f140e3d6
Regards
Sudheer -
Getting the number of rows returned from ResultSet
Hi,
Does anyone know a method to get the number of rows returned with a query using the Resultset class?
Thanks.Hi 281080,
If your database and JDBC driver support it, in order to use the solution that da-alexj has suggested, you need to create a 'scrollable' "ResultSet" -- the javadoc for method "createStatement()" (in class "java.sql.Connection") has more details.
However, I have found with Oracle 8.1.7.4 database and Oracle (thin) JDBC driver, that part of their implementation of the "last()" method (in class "java.sql.ResultSet") is to actually iterate through the entire "ResultSet" in order to reach the last row. If your "ResultSet" is very large (I tested it with a 100,000 row "ResultSet"), this will take a long time.
Just wanted to make you aware of that.
Of-course, this may be irrelevant to you since I didn't see any mention in your post of what database and JDBC driver you are using.
Hope this has helped you, anyway.
Good Luck,
Avi.
Maybe you are looking for
-
my iphone 4 is upadated to ios 7 and now it is always on recovery mode when i switch it off
-
How do i print more than one photo on one page
Iwould like to create a proof page & cain't seem to be abel to find out how to groop multiple pictures on one page
-
Using a variable as part of a url
Hi Thanks for checking in!. I am trying to define one folder in a url as a variable //Here is what my code looks like before I try to use a variable as part of the url. And this works just fine. var nextImage:String = "events/1.jpg"; this.loaderTarge
-
I am interested in monitoring HD coming out of a new 8 core mac pro (which I don't own quite yet). I shoot DVCPRO HD 720/30PN and edit in FCP 6.0.6. I talked to someone at blackmagic and they said their cards don't support 30P (or 30PN) and I would h
-
List PO's waiting to be released
Hi, Is there a standard report to list the PO's waiting to be released ? If not, which tables should I look into to create this list myself in QuickViewer ? Thanks in advance for your feedback, Erik