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.
Similar Messages
-
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 ... -
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 -
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 -
Get records count of all tables
Hi ,
I am trying to get the record count of all tables using dynamic query. I don't know how to put the value in placeholder. I tried the below code.
SET SERVEROUTPUT ON SIZE 1000000
DECLARE
CURSOR table_list
IS
select OBJECT_NAME from user_objects
where object_type in ('TABLE')
and object_name not like '%AUDIT_DDL%'
AND object_name not like 'MD_%'
AND object_name not like 'EXT_%'
AND object_name not like 'STG_%'
AND object_name not like 'SYS_%'
AND object_name not like 'TMP_%'
AND object_name not like 'TEMP_%'
order by 1;
v_count NUMBER :=0;
query_str VARCHAR2(1000);
BEGIN
FOR table_name IN table_list
LOOP
query_str :='SELECT COUNT(1) FROM ' || table_name.OBJECT_NAME;
dbms_output.put_line(query_str);
dbms_output.put_line('Table Name:' || table_name.OBJECT_NAME );
v_count:= execute immediate query_str;
dbms_output.put_line('Table Name:' || table_name.OBJECT_NAME || ', Count ' || v_count );
END LOOP;
END;
I know I am doing wrong in the bold lines. But not sure how to fix it. Please help. Thanks in advance.Hi,
Welcome to the forum!
What you posted is basically right, assuming you really want to do dynamic SQL t all.
The only problem with
961618 wrote:
query_str :='SELECT COUNT(1) FROM ' || table_name.OBJECT_NAME; would be if the object name included special characters (such as single-quotes) or lower-case letters. To avoid any possible problems, I would put the object name inside double-quotes:
... query_str := 'SELECT COUNT (*) FROM "' || table_name.OBJECT_NAME
|| '"';
v_count:= execute immediate query_str;
The correct syntax is
execute immediate query_str INTO v_count;V_count will be the number of rows in a single table. Keep another variable (say total_v_count) that keeps the total count so far.
Do you really need dynamic SQL?
SELECT SUM (num_rows) AS total_rows
FROM user_tables
WHERE table_name NOT_LIKE '%AUDIT_DDL%
AND ...
;gets the same information, accurate as of the last time statistics were gathered, and some of the numbers may be approximate. Depending on how you use the results, that may be good enough for you. If you actually have 10,000,123 rows, and the query says you have 10,000,000, does it really matter? -
Count(*) for all tables
Hi ,
I want the Query to get the table name and count(*) display in excel like this.Can i get count(*) from metadata table .Please let me know ??
ACCT 53
ACCT_CHEQUE 45
EMP 50
DEPT 90Karthick_Arp wrote:
A XML solution.
This one is not mine. This question comes up often in this forum. And once i saw this answer. And i thought its really cool so just saved it in my Google Note Book ;)You need to update your google note book. It doesn't take account of Index Organised Tables.
Based on answer from Laurent Schneider
http://laurentschneider.com/wordpress/2007/04/how-do-i-store-the-counts-of-all-tables.html
SQL> select
2 table_name,
3 to_number(
4 extractvalue(
5 xmltype(
6 dbms_xmlgen.getxml('select count(*) c from '||table_name))
7 ,'/ROWSET/ROW/C')) count
8 from user_tables
9 where iot_type != 'IOT_OVERFLOW';
TABLE_NAME COUNT
DEPT 4
EMP 14
BONUS 0
SALGRADE 5Edited by: BluShadow on Jul 8, 2009 12:00 PM -
I'm trying to get the count for each row to total count for each month
Something like this
Hardware | Jan
Monitors | 5
Processors | 137
Printers | 57
etc........
How can I write a query for this. I can get the Hardware column but don't know how to get the next column.If you can provide more data like sample input DML statements it would have been wonderful..
Assuming is , you need a pivot. Here is an article on basic Pivot..
http://sqlsaga.com/sql-server/how-to-use-pivot-to-transform-rows-into-columns-in-sql-server/
something like this may be..
DECLARE @Input TABLE
Hardware VARCHAR(20),
[Date] VARCHAR(20)
INSERT INTO @Input VALUES('Monitor', '01/01/2014'), ('CPU', '01/01/2014'), ('Monitor', '01/03/2014')
, ('ABC', '01/01/2014'),('Monitor', '02/01/2014')
;WITH CTE AS
SELECT Hardware, LEFT(DATENAME(M, [Date]),3) AS [MonthName] FROM @Input
SELECT *
FROM
SELECT Hardware, [MonthName], COUNT(Hardware) AS Count FROM CTE GROUP BY Hardware, [MonthName]) a
PIVOT (MAX([Count]) FOR [MonthName] IN ([Jan], [Feb])) pvt
Please mark as answer, if this has helped you solve the issue.
Good Luck :) .. visit www.sqlsaga.com for more t-sql code snippets and BI related how to articles. -
Problem w/: Error while getting estimated row count for view
JDev 10.1.3 - Steps
1. created a ADF VO w/ one bind variable vNAME.
2. Created a basic jspx page, use the data control pal. to drop in VO w/ executeparam option. Use the data control pal to drop in VO w/ ADF Read-Only Table w/ select and sort option. Selected all VO columns in table.
3. Following Error msg occurs when running jspx page -
oracle.jbo.DMLException: Error while getting estimated row count for view object CategoryView, statement SELECT count(1) FROM (SELECT
CATEGORY.CATID CATID,
CATEGORY.NAME NAME,
CATEGORY.PICTURE PICTURE,
CATEGORY.ACTIVE ACTIVE
FROM
CATEGORY
WHERE
(CATEGORY.NAME LIKE UPPER(:vName)||'%')) .
Tested SQL Statement in SQL Worksheet works ok (with a Value replacing ':vName').
Can anyone advise - seems to be a straight forward process that is returning this error msg. I have tried variations of the SQL stmt with no luck. The jspx page errors when the ADF Read-Only Table is added.I seem 2 have the same error, in a slightly different situation.
I have a view which subclasses a Entity with a history column 'CreatedOn'. When performing a quick search/filter on this column I get the same error. The ADF app is build on a DB2 database, so no named parameters here. Instead invalid SQL is created when executing the estimated row count. The WHERE clause contains 'CreatedOn = null', should be 'CreatedOn is null'. Furthermore the input of my quick search is not filled in this clause.
Any help would be appreciated -
There was an error while updating row count for "SH".."SH".CHANNELS
Hi All,
Am new to OBIEE.Pls help in this regard.
Am building the physical layer as per Repository guide.When am importing the data in to this,am getting the below error.
*"There was an error while updating row count for "SH".."SH".CHANNELS" :"*
channles is the table name and having 5 rows.
but am able to see the data in the sql prompt. like SELECT * FROM SH.CHANNELS then 5 rows data would be displaying..
pls help in this regard and where is the excat problem?
Thanks,what is the error?
Make sure that your connection pool settings are okay..
Make sure that, you are using correct driver in case of if you are using ODBC dsn..
Also make sure that, your oracle server is running... TNS and Oracle server services -
Can we get row counts when using dbms_datapump?
When using dbms_datapump, is there a way to get the rows loaded for each table, similar to the log files when using the command line? I can't seem to find anything. I'm trying to import. Database is 10g r2.
if you don't have to use DBMS_DATAPUMP and can use external tables for the import (both work exactly same way), then you can use ROWCOUNT
INSERT INTO MYTABLE SELECT * FROM EXTERNALTABLE;
v_number_of_rows := SQL%ROWCOUNT ;
COMMIT;
if you have to use DBMS_DATAPUMP then look at "worker status types" in this document
http://www.stanford.edu/dept/itss/docs/oracle/10gR2/appdev.102/b14258/d_datpmp.htm#i997417 -
Rows count for repetitive groups in tablix.
Hi All,
To make the story cut short, i will going to explain my scenario:
i have a tablis contro and i garoup it by a field say "Field1" which contains A and B values,
in my case we divide groups in two parts if it has rows more then 200.
so, my report output and my required is below :
Current Output -------------------------- Required layout
here 200, 20, 30 are number of rows per group.
now my requirement is if a group is repetitive
i need the all rows count for that value like in above case :
Header text of Group A should be like : A(220) i.e 200 +20
please help me on this...
it is very urgent for me
shashankhi Simon,
thanks for reply, sorry, i skipped to mentioned that i have to provide multilevel grouping also, like
Group By: Field 1 -> Field 2 -> field3
so, to achieve my requirement by Sql as solution has no problem if i do not have multilevel grouping, but i have to provide that and in that case the query will be like,
“select distinct [column1],[Column2],[Column3],count(*) as rn from [table] group by [column1],[Column2],[Column3]”
which is problematic in my case.
so for doing this i need a solution apart from sql but by using SSRS Report end.
Thanks again.
Shashank -
Single row editing for multiple tables in a single page
Hi!
I have split a table with many many columns into more tables with a lower number of columns. There is an ID column (sequence generated) that is Primary Key common for all tables. Obviously, the relationship between these tables is 1 to 1, so its not about having to build master-detail pages.
What I need now is to edit all these tables in a single page: one single row from each table. The Automated Row Fetch & Automatic Row Processing (DML) processes used for the old table must be replaced by something else.
Is there a way to use in a single page more pairs of such processes for more tables?
I want to avoid manually writing processes with lot of PL/SQL code to handle row fetch & update.
Keep in mind that the page will have an ID item that can be used to identify unique rows in all my tables.
Thanks,
SorinI have split a table with many many columns into more tables with a lower number of columns
IMHO that is a very bad idea. There is nothing wrong with having many columns in a table. If you would like to split them to better "categorize" them, just create views on the table and expose different subsets of the columns.
I want to avoid manually writing processes with lot of PL/SQL code to handle row fetch & update.
That is unavoidable given how you have designed the underlying tables.
You could try creating a view that joins all the tables by the PK and creating a form based on that view. Then write a INSTEAD OF trigger on the view that "doles out" the DML on the view to each of the underlying tables. -
Trying to access row values in a table which does not have any rows yet
try{
MappedRecord importParams = recordFactory.createMappedRecord("CONTAINER_OF_IMPORT_PARAMS");
IFunction function1 = client.getFunctionsMetaData().getFunction(funModGetDet);
IStructureFactory strucFact = interaction.retrieveStructureFactory();
response.write("try2 :"+pnumber);
IRecord structure = (IRecord) strucFact.getStructure(function1.getParameter("PERNR_TAB").getStructure());
response.write("try111 :"+pnumber);
structure.setString("PERNR",pnumber);
I am getting the following error "Trying to access row values in a table which does not have any rows yet " where PERNR_TAB is a table containing field "PERNR".
Can anybody help me out?Please re-post this question in the appropriate forum. It seems to have nothing to do with Web Dynpro.
-
Extract schema/metadata - names for all tables and attributes
Hi, I am quite new to Oracle DB (only been doing dev mostly with sqlserver before). Is there a way to extract schema (names for all tables and attributes) for 10g and 11g in application code (either java or .net) or pl/sql?
Thank you,
-TonyThere are built in views that start with DBA_, ALL_, and USER_. All means all the user can see, user means all the user has, and dba means everything, which generally means the same as the others plus an owner. So you can desc user_tables to see what-all that view has, then select columns from the view with ordinary sql. See the doc set for all the views available, interesting ones are ...views, ...objects, ...tab_cols and so forth.
There are also built in procedures for getting metadata, google for details.
Many tools have easy GUI's for this too. EM has ways on the administration screen to get to various objects, and then you can show the ddl. Maybe sqldeveloper has something too. -
I keep getting ' user not register for online ' when trying to get track names for my CD imports for Windows 7 and I'm unable to find a solution.
I can't be certain exactly which steps are going to be needed in each case, but if you work through this in sequence hopefully one of the steps will prove effective.
First try this:
With iTunes closed.
Press the WinLogoKey+R
Type in %appdata% and press return
Double click on Apple Computer
Double click on iTunes
Delete the file CD Info.cidb
Start iTunes and try again.
If that doesn't work close iTunes and try deleting com.apple.iTunes.Gracenote.plist in the same folder.
If that doesn't work close iTunes and try deleting iTunesPrefs.xml. This will reset your some of your preferences in iTunes so be sure to check them and reset as required.
If that still hasn't resolved things close iTunes and try deleting the entire %appdata%\Apple Computer folder or look for parallel files/folders in the C:\Users\<User>\AppData\Local or C:\Users\<User>\AppData\LocalLow in case a corrupt file is persisting there.
Note that any iOS device backups are stored in the MobileSync folder within Apple Computer. Once things are working you should backup your devices again as soon as possible.
Or it might not be the preference files after all...
For general advice see Troubleshooting issues with iTunes for Windows updates.
The steps in the second box are a guide to removing everything related to iTunes and then rebuilding it which is often a good starting point unless the symptoms indicate a more specific approach. Review the other boxes and the list of support documents further down page in case one of them applies.
Your library should be unaffected by these steps but there is backup and recovery advice elsewhere in the user tip.
tt2
Maybe you are looking for
-
Delivery split and delivery consolidation
Experts, Can anyone help me with the following query? We are dealing with cables and have an unique requirement. When we create a sales order, due to availability check the line item had created 3 schedule lines for different dates. In turn this has
-
How can I tell if there is a Kinect 2.0 sensor attached? C#
I know there were several ways to do this in the old SDKs, versions 1.5 - 1.8, but how can you do it in 2.0? I've searched through a tonne of forums to try to find this answer as well as combing through the Kinect 2.0 API. I don't want to have to res
-
Dear All, I have working on a file to JDBC scenario, while i am executing the scenario I am getting the following error message in receiver JDBC. Error while parsing or executing XML-SQL document: Error processing request in sax parser: No 'action' a
-
Tttle says it all. This is a fairly new printer. Using genuine HP ink.
-
Cannot add new column in Access 2013
I am using Microsoft Access 2013, and I am unable to add a new column to a table in Design Mode. I can add a new column in Datasheet Mode, but not in Design.