Row Count mismatch in a table
Hi,
I am having a table and if i do count(*) , the total rows are coming 36882, but if i take export backup or select * from table, it is showing 7225. Any help to trace out the problem is highly appreciated. I am using oracle 9.2.0.4 in aix 5.3
Regards
Sridhar
Is the "table" being selected from and rows counted, an actual table? Confirm using ALL_OBJECTS. What is the table type? Hash?
s. I have counted in the actual table only. From all_objects, the object type is TABLE.
Is FGAC (Fine Grain Access Control) used? Have you tried the select count or export from the SYS schema (exempt from FGAC)? Have you looked at the execution plans?
No FGAC is used in that table. Export taken from sys also. Then also the same problem.Execution plan has been verified.
If full table scan is performed, then less number of rows are returned. If the index hint is used and give count(*) or select * from table_name, all rows are returned.
What happens when a CTAS is done against this table - what is the rowcount of the new table?
if we give select * from alone then 7000+ rows alone created in new table.
If index hint is used for ctas, then all the rows nearly 38000 rows are created in the new table.
There are numerous sanity checks to do, before "accusing" a table of showing incorrect and buggy row count totals
- All levels of trouble shooting has been already done and no use. This is the second time, i am facing this problem.
Hence raised the issue and requested help from others.
Similar Messages
-
Getting row count of file into table column
Hi experts,
I want to insert the row count of the file into a table column for generating a summary file containing the detials of all the files generated for the day along with the row count and also for audit purpose.
My design is to create table in the summary file format & update the data's in it then using OdiSqlUnload to generate the required summary file, for this purpose I need to insert the row count of the file generated.
I tried to get the row count using the http://odiexperts.com/get-file-length-and-header-in-operator post. But passing the "lines" value into a ODI variable or inserting into a table column is not working.
Please help or suggest what can be done to achive the above scenario.
Thanks in advance.There are a few excellent examples at :- COUNT
Cheers
John
http://john-goodwin.blogspot.com/ -
GETTING ROW COUNTS OF ALL TABLES AT A TIME
Is there any column in any Data dictionary table which gives the row counts for particular table..
My scenario is...i need to get row counts of some 100 tables in our database...
instead of doing select count(*) for each table....is there any way i can do it?
similary How to get column counts for each table..in database .For example
Employee table has 3 columns...empid,empname,deptno....i want count(empid),
count(empname),count(deptno) ...is there any easy way for finding all column counts of each table in data base? is it possible?Why does "select count(mgr) from emp" return null and not 13?Good question ;)
Seems that xml generation in principle can't handle »counting nulls«:
SQL> select xmltype(cursor(select null c from dual)) x from dual
X
<?xml version="1.0"?>
<ROWSET>
<ROW>
</ROW>
</ROWSET>
1 row selected.
SQL> select cursor(select count(null) c from dual) x from dual
Cur
0
1 row selected.
SQL> select xmltype(cursor(select count(null) c from dual)) x from dual
select xmltype(cursor(select count(null) c from dual)) x from dual
Error at line 1
ORA-31011: XML parsing failed
ORA-19202: Error occurred in XML processing
LPX-00229: input source is empty
Error at line 0
ORA-06512: at "SYS.XMLTYPE", line 0
ORA-06512: at line 1
but
SQL> select xmltype(cursor(select count(1) c from dual)) x from dual
X
<?xml version="1.0"?>
<ROWSET>
<ROW>
<C>1</C>
</ROW>
</ROWSET>
1 row selected.Looks like a bug to me ... -
I have code that has the line "rowNum = objXLAppln.Range("A" & Rows.Count).End(xlUp).Row". Every once in a while the macro crashes on this line. It doesn't happen regularly or with a pattern. The entire code is below. I have several
modules that use this line of code. Any ideas?
Function ImportScores()
Dim RecSet As DAO.Recordset
Dim objXLAppln As Excel.Application
Dim objWBook As Excel.Workbook
Dim rowNum As Variant
Dim i As Integer
Dim j As Integer
Dim StrPathFile As String, strFile As String, strPath As String
Dim strBrowseMsg As String, strInitialDirectory As String, strFilter As String
'show dialogue box
strBrowseMsg = "Select the EXCEL file:"
'set directory to load files from
strInitialDirectory = "C:\Bridge_CIP_Part-A_B\"
'run strFilter function
strFilter = ahtAddFilterItem(strFilter, "Excel Files (*.xlsx)", "*.xlsx")
StrPathFile = ahtCommonFileOpenSave(InitialDir:=strInitialDirectory, _
Filter:=strFilter, OpenFile:=True, _
DialogTitle:=strBrowseMsg, _
Flags:=ahtOFN_HIDEREADONLY)
If StrPathFile = "" Then
MsgBox "No file was selected.", vbOK, "No Selection"
Exit Function
End If
'Set Excel application object. Critical for macro to run properly. Do not change.
Set objXLAppln = New Excel.Application
'Open workbook and worksheet to load data.
With objXLAppln
Set objWBook = .Workbooks.Open(StrPathFile)
objXLAppln.Visible = True
End With
Set RecSet = CurrentDb.OpenRecordset("Performance_Scores")
'Copy data from Excel cells to Access fields
objXLAppln.Sheets("Performance_Attributes").Select
rowNum = objXLAppln.Range("A" & Rows.Count).End(xlUp).Row
objXLAppln.Range("A10").Select
'Add records to table from Excel
With RecSet
For i = 0 To rowNum - 9
RecSet.AddNew
RecSet.Fields("CIP_ID").value = objXLAppln.ActiveCell.Offset(i, 0).value
RecSet.Fields("5YearScore").value = objXLAppln.ActiveCell.Offset(i, 53).value
RecSet.Fields("10YearScore").value = objXLAppln.ActiveCell.Offset(i, 54).value
RecSet.Fields("15YearScore").value = objXLAppln.ActiveCell.Offset(i, 55).value
RecSet.Fields("20YearScore").value = objXLAppln.ActiveCell.Offset(i, 56).value
RecSet.Update
Next i
End With
'Close everything
RecSet.Close
objWBook.Close SaveChanges:=False
objXLAppln.Quit
Set RecSet = Nothing
Set objWBook = Nothing
Set objXLAppln = Nothing
End FunctionI rewrote as below.
But rather than doing it this way, I would create a linked table to this workbook and import the data using an Append query.
Function ImportScores()
Const FOOTER_ROWS_TO_SKIP As Integer = 10
Const COL_CIP_ID As Integer = 1
Const COL_5YEARSCORE As Integer = 54
Dim RecSet As DAO.Recordset
Dim objXLAppln As Excel.Application
Dim objWBook As Excel.Workbook
Dim objXLSheet As Excel.Worksheet
Dim rowNum As Variant
Dim row As Integer
Dim j As Integer
Dim StrPathFile As String, strFile As String, strPath As String
Dim strBrowseMsg As String, strInitialDirectory As String, strFilter As String
'show dialogue box
strBrowseMsg = "Select the EXCEL file:"
'set directory to load files from
strInitialDirectory = "C:\Bridge_CIP_Part-A_B\"
'run strFilter function
strFilter = ahtAddFilterItem(strFilter, "Excel Files (*.xlsx)", "*.xlsx")
StrPathFile = ahtCommonFileOpenSave(InitialDir:=strInitialDirectory, _
Filter:=strFilter, OpenFile:=True,
DialogTitle:=strBrowseMsg,
Flags:=ahtOFN_HIDEREADONLY)
'StrPathFile = "C:\Users\Tom\Documents\test.xlsx" 'testonly
If StrPathFile = "" Then
MsgBox "No file was selected.", vbOK, "No Selection"
Exit Function
End If
'Set Excel application object. Critical for macro to run properly. Do not change.
Set objXLAppln = New Excel.Application
'Open workbook and worksheet to load data.
With objXLAppln
Set objWBook = .Workbooks.Open(StrPathFile)
objXLAppln.Visible = True
Set objXLSheet = objXLAppln.Sheets("Performance_Scores")
End With
rowNum = objXLSheet.UsedRange.Rows.Count
'Add records to table from Excel
Set RecSet = CurrentDb.OpenRecordset("Performance_Scores", dbOpenDynaset)
With RecSet
For row = 1 To rowNum - FOOTER_ROWS_TO_SKIP
RecSet.AddNew
RecSet.Fields("CIP_ID").Value = objXLSheet.Cells(row, COL_CIP_ID).Value
RecSet.Fields("5YearScore").Value = objXLSheet.Cells(row, COL_5YEARSCORE).Value
'etc.
RecSet.Update
Next row
End With
'Close everything
RecSet.Close
objWBook.Close SaveChanges:=False
objXLAppln.Quit
Set RecSet = Nothing
Set objWBook = Nothing
Set objXLAppln = Nothing
End Function
-Tom. Microsoft Access MVP -
Most efficient way to get row count with a where clause
Have not found a definitive answer on how to do this. Is there a better way to get a row count from a large table that needs to satisfy a where clause like so:
SELECT COUNT(*) FROM BigTable WHERE TypeName = 'ABC'
I have seen several posts suggesting something like
SELECT COUNT(*) FROM BigTable(NOLOCK);
and
selectOBJECT_NAME(object_id),row_count from sys.dm_db_partition_stats
whereOBJECT_NAME(object_id)='BigTable'but I need the row count that satisfies my where clause (i.e.: WHERE TypeName = 'ABC')It needs index to improve the performance.
- create index on typename column
- create a indexed view to do the count in advance
-partition on type name (although it's unlikely) then get count from the system tables...
all those 3 solutions are about indexing.
Regards
John Huang, MVP-SQL, MCM-SQL, http://www.sqlnotes.info -
Hi,
We have CDC enabled for some tables in sql server 2008 R2. We are using this CDC table for incremental load on daily basis by providing From date(11/20/2014 12:00:000 AM) and To date(11/21/2014 00:00:000 AM). However, we see that there is a count mismatch
when we query the cdc table between the same time frame after the increamental load completed. Count mismatch is not due to the multiple records beacuse of Operation Flag, We are considering only the distinct Primary Key for taking count.
Kindly do the needful.Hi Visakh,
PFB the query logic,
;WITH CTE
AS (
SELECT ROW_NUMBER() OVER (PARTITION by CAST(sys.fn_cdc_map_lsn_to_time(__$start_lsn) AS DATE),<PrimaryKey> ORDER BY __$start_lsn DESC,__$seqval DESC,__$operation DESC) [ROWNUMBER],
sys.fn_cdc_map_lsn_to_time(__$start_lsn) [TRAN_DT],
FROM cdc.fn_cdc_get_all_changes_DBO_<Tablename>(
(SELECT sys.fn_cdc_increment_lsn(sys.fn_cdc_map_time_to_lsn('smallest greater than', '11/20/2014 12:00:00 AM'))),
(SELECT sys.fn_cdc_map_time_to_lsn('largest less than or equal', '11/21/2014 12:00:00 AM')),'all update old')
SELECT * FROM CTE WHERE ROWNUMBER = 1
Are you sure count difference is not because of all update old?
When you use all update old it returns two rows for each update ie one with old and one with new values.
see
http://msdn.microsoft.com/en-IN/library/bb510627.aspx
Please Mark This As Answer if it solved your issue
Please Mark This As Helpful if it helps to solve your issue
Visakh
My MSDN Page
My Personal Blog
My Facebook Page -
How to add the Row count(number of rows in table) in the table header?
Hi,
I'm having a table. This table is viewed when i click on a search button.
<b>On the table header it should dynamically display the number of rows in the table, i.e., the row count.</b>
How to do this? could any one explain me with the detailed procedure to achieve this.
Thanks & Regards,
SureshIf you want to show a localized text in the table header, you should use the <b>Message Pool</b> to create a (parameterized) message "tableHeaderText" like "There are table entries".
Next, create a context attribute "tableHeaderText" of type "string" and bind the "text" property of the table header Caption UI element to this attribute.
Whenever the table data has changed (e.g. at the end of the supply function for the table's data source node), update the header text:
int numRows = wdContext.node<TableDataSourceNode>().size();
String text = wdComponentAPI.getTextAccessor().getText
IMessage<ComponentName>.TABLE_HEADER_TEXT,
new Object[] { String.valueOf(numRows) }
wdContext.currentContextElement().setTableHeaderText(text);
Maybe you want to provide a separate message for the case that there are no entries.
Alternatively, you can make the attribute calculated and return the header text in the attribute getter.
Armin -
How to get row count(*) for each table that matches a pattern
I have the following query that returns all tables that match a pattern (tablename_ and then 4 digits). I also want to return the row counts for these tables.
Currently a single column is returned: tablename. I want to add the column RowCount.
DECLARE @SQLCommand nvarchar(4000)
DECLARE @TableName varchar(128)
SET @TableName = 'ods_TTstat_master' --<<<<<< change this to a table name
SET @SQLCommand = 'SELECT [name] as zhistTables FROM dbo.sysobjects WHERE name like ''%' + @TableName + '%'' and objectproperty(id,N''IsUserTable'')=1 ORDER BY name DESC'
EXEC sp_executesql @SQLCommandThe like operator requires a string operand.
http://msdn.microsoft.com/en-us/library/ms179859.aspx
Example:
DECLARE @Like varchar(50) = '%frame%';
SELECT * FROM Production.Product WHERE Name like @Like;
-- (79 row(s) affected)
For variable use, apply dynamic SQL:
http://www.sqlusa.com/bestpractices/datetimeconversion/
Rows count all tables:
http://www.sqlusa.com/bestpractices2005/alltablesrowcount/
Kalman Toth Database & OLAP Architect
SQL Server 2014 Design & Programming
New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012 -
Trying to get row counts for all tables at a time
Hi,
i am trying to get row counts in database at a time with below query but i am getting error:
its giving me ora-19202 error..please advise me
select
table_name,
to_number(
extractvalue(
xmltype(dbms_xmlgen.getxml('select count(*) c from '||table_name))
,'/ROWSET/ROW/C')
count
from all_tables;ALL_TABLES returns tables/views current user has access to. These tables/views are owned not just by current user. However your code
dbms_xmlgen.getxml('select count(*) c from '||table_name)does not specify who the owner is. You need to change it to:
dbms_xmlgen.getxml('select count(*) c from '||owner || '.' || table_name)However, it still will not work. Why? As I said, ALL_TABLES returns tables/views current user has access to. Any type of access, not just SELECT. So if current user is, for example, granted nothing but UPDATE on some table the above select will fail. You would have to filter ALL_TABLES through ALL_SYS_PRIVS, ALL_ROLE_PRIVS, ALL_TAB_PRIVS and PUBLIC to get list of tables current user can select from. For example, code below does it for tables/views owned by current user and tables/views current user is explicitly granted SELECT:
select
t.owner,
t.table_name,
to_number(
extractvalue(
xmltype(dbms_xmlgen.getxml('select count(*) c from '||t.owner || '.' || t.table_name))
,'/ROWSET/ROW/C')
count
from all_tables t,user_tab_privs p
where t.owner = p.owner
and t.table_name = p.table_name
and privilege = 'SELECT'
union all
select
user,
t.table_name,
to_number(
extractvalue(
xmltype(dbms_xmlgen.getxml('select count(*) c from '||t.table_name))
,'/ROWSET/ROW/C')
count
from user_tables t
OWNER TABLE_NAME COUNT
SCOTT DEPT 4
U1 QAQA 0
U1 TBL 0
U1 EMP 1
SQL> SY. -
How to get the row count of a Table DATA?
Hi,
In my Adobe form layout, I have a Table node which is bound to an internal table. Now at runtime, I want to determine the number of rows that the internal table has, i.e the row count of the DATA node of the Table. How will I be able to determine the no. of rows of the internal table at runtime using Javascript? I am not being able to find any suitable answer in this forum. Please suggest. Thanks in advance.Hi,
If you bind the interactive form table to the internal table and specify some properties, the table will vary its row size according to the number of data available in the internal table.
You have to wrap the table in a sub form, check 'allow page break with contents' and property 'flowed'.
the table will automatically increase its row size...
Is this the reason for which you wanted for the row count..?
If so, this will help you..
Regards.
Surya -
Unique row count in table footer
JDev 11.1.1.6
Hi,
In my current table, I am able to show total row count at a table footer by using #{bindings.<myVO>Iterator.estimatedRowCount}.
I have a request from my user to show unique total row count. For example rows below:
1 A
2 B
3 A
4 C
The footer should show:
4 3
The second column has A, B, and C where A is counted only 1 (unique). Is there a way to achieve this?
Thanks.Hi RRA,
This may work for a static # of rows (no filtering). In the table I use, I can do filtering and that certainly will make the count result be different if I use another VO for distinct result.
Thanks. -
Getting the count of rows present in the oracle table
Hi all,
i want to get the total number of rows present in the sql table to the appmodule.
After applying the some view criteria to the view object. if it try with getallrowsinrange it was giving count of rows present in the viewobject but i want total number of rows present in the sql table.
How can i get that
I am using jdev 11.1.1.5
Thanks in advanceI threw something together, quick and dirty, feel free to optimize.
Assuming that you want the table count, I put the code into a EntityDefImpl subclass since this is what represents a table in the middle-tier.
public class EmpDefImpl
extends EntityDefImpl {
* This is the default constructor (do not remove).
public EmpDefImpl( ) {}
//~ Methods ****************************************************************************
public long getTableRowCount( DBTransaction transaction ) {
String query = getQuery( );
String countQuery = String.format( "SELECT COUNT(*) FROM (%s)", query );
long count = 0;
ViewObject vo = transaction.createViewObjectFromQueryStmt( countQuery );
try {
vo.executeQuery( );
Row row = vo.first( );
Number number = (Number)row.getAttribute( 0 );
count = number.longValue( );
} finally {
vo.remove( );
return count;
}Depending on your type map, you might not get a oracle.jbo.domain.Number, but something else, so the cast might need correction.
Usage example:
public class EmpEditViewImpl extends ViewObjectImpl {
public EmpEditViewImpl() {
protected void executeQueryForCollection( Object object, Object[] object2, int i ) {
super.executeQueryForCollection( object, object2, i );
EmpDefImpl def = ( EmpDefImpl )getEntityDef( 0 );
long tableRowCount = def.getTableRowCount( getDBTransaction() ) );
// Do something with it
}As you can see, the code is pretty generic. You might also be able to put this into an ADF extension base class.
Sascha
Edited by: Sascha Herrmann on Jun 7, 2012 2:39 PM -
Get row count for different tables to the same line
How can I get the row count for different tables in one line:
SELECT count(A), count(B), count(C) from table tb_a A , tb_b B, tb_c C;
Thanks!>
Hi,
How can I get the row count for different tables in one line:
SELECT count(A), count(B), count(C) from table tb_a A , tb_b B, tb_c C;Something like this? One of the many uses for CTE's - Common Table Expressions - AKA
subquery refactoring. Worth getting to know - very handy!
with acount as
select count(*) as counta from dual -- put your table name here
bcount as
select count(*) as countb from dual -- put your table name here
ccount as
select count(*) as countc from dual -- put your table name here
select a.counta, b.countb, c.countc from acount a, bcount b, ccount c;HTH,
Paul...
Edited by: Paulie on 25-Jul-2012 17:44 -
hi folks,
How to get a tables' row count (number of records)?
Values of table are filled by an RFC return structure. Or how can we get the number of records in the RFC return structure?
thanks in advance
nikhilHi,
Check the size of the node bound to the table
lets say orders is the node bound to the table
//Replace orders with the node bound to your table.
wdContext.nodeOrders().size();
Regards
Ayyapparaj -
Row count for tables from 2 different databases
Hi,
i wrote a query to get counts from all the tables in one schema to another schema. this generates the select count (*) from tables and gives me the counts, but i want to get the counts such as
table1 -- 100 -- DB1
table1 - 110
table2 - 230 - DB2
table2 - 230 etc...
here is my query that works but display of the output is the way i wanted. can someone help me getting the output as above described.
select 'select ''PTO'', count(*) as '||(table_name)||'_count'||' from '||table_name||';'from dba_tables
where owner = 'TEST'
union all
select 'select ''PFO'', count(*) as '||(table_name)||'_count'||' from '||table_name||';'from [email protected]
where owner = 'TEST';
thanks...DUPLICATE post
count of rows in a schema tables
Maybe you are looking for
-
ColdFusion 11 Scheduled Task & IIS 7.5
I have a scheduled task registered in ColdFusion 11 Admin console. ColdFusion 11 is hosted over IIS 7.5. The schedule task is to run 1 perticular file from sub application of the main app. After upgrading application from ColdFusion 9 to ColdFusion 1
-
How to Capitalize the First Letter in Every Word in Mysql
Hi, I have been trying to tidy up a massive database where visitors have been sloppy when entering text. The main thing I want to do is to Capitalize The First Letter In Every Word In Mysql. I have found the code below in PHP but it keeps finding an
-
Monitor on timeline goes black...
Using the latest version of Premiere Pro, what causes the monitor to go black on the timeline?
-
Issue in MI31 Transaction - Physical Inventory Document
Hi All, We are creating Physical Inventory documents using MI31 transaction for all storage locations by passing Material and plant. We are getting error message as " A system error has occured while locking". We are getting this message only for a p
-
Hello. How do I run a weblogic platform portal 8.1 on a weblogic server 7.0 service pack 4? Is that a supported configuration? any problems / Issues ? Weblogic Integrator