Count the number of rows in each table
I have a list of table names, how to I write a query to find out the row count of each table.
select table_name from all_tables a where owner='XXX' and num_row > 100
or
select table_name from all_tables a where owner='XXX' and sample_size > 100
doesn't quite work.
Why?
Thanks in advance,
Edited by: mpt_fz on Jan 12, 2010 12:06 PM
Well, then another method learned from Michael ;)
scott@ORCL>
scott@ORCL>select * from v$version;
BANNER
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
PL/SQL Release 11.1.0.6.0 - Production
CORE 11.1.0.6.0 Production
TNS for 32-bit Windows: Version 11.1.0.6.0 - Production
NLSRTL Version 11.1.0.6.0 - Production
Elapsed: 00:00:00.14
scott@ORCL>
scott@ORCL>
scott@ORCL>select table_name,
2 DBMS_XMLGEN.getxmltype(
3 'select count(*) c from '||table_name
4 ).extract('//text()').getnumberval() tot_rows
5 from user_tables
6 where iot_type is null
7 or iot_type != 'IOT_OVERFLOW';
TABLE_NAME TOT_ROWS
A_TEST_TB_CASHFLOW 14
TEST_DUMMY 1
A_TEST_TB_CASHFLOW_N 1
TEST_CAST 1
DEPT 4
EMP 14
BONUS 0
SALGRADE 5
EMP_DETAILS 3
T_EMP 0
AUDIT_T 0
TABLE_NAME TOT_ROWS
C_C 4
TRAIN_DET 2
TEST_COM_IMP 2
TIME_P 1
PRI_UQ 4
TEST_CHK 0
ANSHUMANSAHAISGENIOUS 1
T 1
XEUROPE 2
D_D 8
PUBLICTRANSPORT 4
TABLE_NAME TOT_ROWS
XASIA 2
TF1 0
TEST_HH 14
TEST_SWAP 4
REVIVE_XML 3
XGMT 1
CUSTOMER_DET 1
FOURWHEELER 2
SPOOL_LOG 13
CITYTRANSPORT 8
T1 2
TABLE_NAME TOT_ROWS
T2 2
A_A 1
B_B 2
AUTOMOBILE 1
XDUAL 1
S_TEMP 0
39 rows selected.
Elapsed: 00:00:08.78
scott@ORCL>Regards.
Satyaki De.
Similar Messages
-
Hi
How to find the number of rows in each table of a database by just using a SQL query,
and should not use the data dictionary tables also... is there any way...??
Thanks
MJIt can be done in a single SQL like ->
satyaki>
satyaki>select * from v$version;
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
PL/SQL Release 10.2.0.1.0 - Production
CORE 10.2.0.1.0 Production
TNS for Linux: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production
Elapsed: 00:00:00.00
satyaki>
satyaki>
satyaki>SELECT table_name,
2 DBMS_XMLGEN.getxmltype ('SELECT Count(*) c FROM ' || table_name).EXTRACT ('//text()').ge
tnumberval() tot_rows
3 FROM user_tables;
TABLE_NAME TOT_ROWS
QUESTIONTYPE 0
SRGROUPTABLE 1
ST_TEST 4
REGISTER 0
DEB_1 2
EMP1 0
6 rows selected.
Elapsed: 00:00:12.04Credit goes to Michael. ;)
Regards.
Satyaki De. -
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 -
Counting the number of occurences in a table column
Hi All
I have a table with a column that contains approx. 5000 6-digit codes. A number of these codes are duplicted in the column, and I want to count the number of occurences of each code. The column looks a bit like -
WCID
940042
920012
940652
940199
188949
155146
155196
174196
152148
151281
196209
174015
182163
195465
195318
182008
189589
150675
There can be mulitple instances of each WCID and I need to count the number of instances of each. I also have access to another table that also has a column of each WCID, but only once - ie no multiple instances. The second table is identical except that there are only single instances of each WCID.
I thought I could either loop through on the table to be counted, from 100000 to 999999 and count each occurence that way, but it would be very inefficient. The other way I thought would be to perhaps select a WCID from the unique table, count the occurence of that, select the next WCID from the unique table, count that and so on, however I'm not sure how to do it in PL/SQL. Perhaps select the WCID from the unique table into a cursor, loop through that and compare it with the original table and count the instances?
I hope this makes some sense, any help would be really appreciated
Thanks
BillHi, Bill,
That sounds like a job for GROUP BY:
SELECT wcid
, COUNT (*) AS num_found
FROM table_x
GROUP BY wcid
ORDER BY wcid
I hope that answers your question.
If not, post CREATE TABLE and INSERT statements for a little sample data, and the results you want from that data. -
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 -
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. -
Displayin message and fixing the number of rows in a table
Hi Experts,
I have a requirement like this
there is a table, where i need to diplay a message when there are no records and no rows should be visible on that table.
Also, when the records are populated from the context, i need to fix the number of rows in that table and display the records.
Please let me know hw this can be achieved.
Also in the table I have Link to URL, please let me know how to handle this reference, when i set the reference Property, its giving me an error stating that the file doesn't exist when the table gets loaded.
Thanks in Advance
Regards,
PalaniHi
Oh!! You should to explain it at first thread itself that you want to display a JPG imange or other WDWebResourceTypetaken form the backend.
1. So this is not at all a URL
2. You have to convert binary data to WDWebResource then display it in either Image UI element or other (like PDF , txt etc)
3
try
// Read the datasource of the FileUpload
IWDResource res = wdContext.currentContextElement().getResource();
InputStream in = res.read(false);
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
int length;
byte[] part = new byte[10 * 1024];
while ((length = in.read(part)) != -1)
bOut.write(part, 0, length);
in.close();
bOut.close();
IPrivateUploadCompView.IImageTableElement ele = wdContext.nodeImageTable().createImageTableElement();
ele.setImage(wdContext.currentContextElement().getResource().getUrl(0));
ele.setText(res.getResourceName());
wdContext.nodeImageTable().addElement(ele);
catch (Exception e)
wdComponentAPI.getMessageManager().reportWarning(e.toString());
Here I assume that you convert that data to IWDResource type or
4.
WDWebResource.getWebResource(wdContext.currentContextElement().getresource(), type);
// getResource of type binary which u read from BAPI and set it in local context , type is MIMETYPE or hardcode it as "JPG"
5. Further help
[Help1|To Displayan Image in Webdynpro Java from Standard Function Module;
[Help2|http://wiki.sdn.sap.com/wiki/display/KMC/GettinganimagefromKMDocumentstobeusedinWeb+Dynpro]
[Help3|http://wiki.sdn.sap.com/wiki/display/KMC/GettinganimagefromKMDocumenttobeusedinWeb+DynPro]
It might code look strange at first , please do some reserch in SDN ,I did my best at this level.
Best Regards
Satish Kumar -
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. -
Count the number of lines in each file in a directory
Hello,
I would like to count the number of lines for each file in my directory and subdirectories.
I wonder how can I count the lines of the specified files?
Here is the program which is listed the files in the specified directory:
String path = "C:/User/Studies/Pracices/src/Pract1";
String files;
File folder = new File(path);
File[] listOfFiles = folder.listFiles();
for (int i = 0; i < listOfFiles.length; i++)
if (listOfFiles.isFile())
files = listOfFiles[i].getName();
System.out.println(files);Ok so one more question.
Actually my path is pointing to one Directory and like here I can just read from one file that the name of the file should be specified in the path is it possible to help me in that part?
File f = new File("C:/User/Studies/Practices/src/Pract1/");
FileReader fr = new FileReader(f);
BufferedReader br = new BufferedReader(fr);
String str = br.readLine();
LineNumberReader ln = new LineNumberReader(br);
int count = 0;
while (ln.readLine()!=null)
count++;
System.out.println("no. of lines in the file = " + count); -
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
GaryDeclare
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 -
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 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
Maybe you are looking for
-
Mac Pro 2.66, New Memory & Repeated KPs
Hi all I've had 4GB of RAM in my Mac Pro for some time now, in the following config Riser A - 2x1GB, EMPTY Riser B - 2x512MB, 2x512MB I recently upgraded to another 2x1GB, which I put in the empty slots of Riser A... I did this back in February or so
-
Hi Based on instruction provided in the document below I have created a simple java class to pull back all pages created through the Page Service API. http://download.oracle.com/docs/cd/E14571_01/webcenter.1111/e10148/jpsdg_page_service.htm#BABFEDAH
-
'Hi Experts, I am Working in SAP Bw. My process Chain Has Sequence of Steps. Order of Step (1) Start (2) Load data (3) Acr (4) ABAP Program to delete data from Open Hub
-
Mail version 2.1 in iMac running 10.4.10 , everything is ok, I got my mail, but when I try to open the Mail Prefrerences it just don't show, click on that, nothing happens. I already try to replace the com.apple.mail.plist the only thing it does it w
-
I have a VOB file that I need to be anything that iMovie can edit. It's on a cd (yes a cd, not a dvd) because the mimi-dvd won't go in my macbook drive. I've tried streamclip, and it doesn't do anything but give me errors. DiVA won't even OPEN. Nor w