Oracle Select !

Hi Expert,

Can anybody please through light on below query! How does it's work internally?

select table_name,
to_number(extractvalue(dbms_xmlgen.getXMLtype('select /*+ PARALLEL(8) */ count(*) cnt from "&&SCHEMA_NAME".'||table_name),'/ROWSET/ROW/CNT'))
rows_in_table from dba_TABLES
where owner='&SCHEMA_NAME';

MIHIR KAR#Hadoop #Oracle_DB #UNIX beginnerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

slightwv (䄆 Netminder) Commented:
It selects a count from a table using dynamic SQL:
select /*+ PARALLEL(8) */ count(*) cnt from "&&SCHEMA_NAME".'||table_name

It creates an XML resultset by looing through DBA_TABLES using the dbms_xmlgen.

It then extracts the count from the XML with extractvalue.

and returns the table_name and the row count for a specific schema.

Break it down and experiment.

I'm guessing you already know:
select count(*) from some_table;

To play with the xml generate:
select dbms_xmlgen.getXMLtype('select sysdate from dual') from dual;

Then you can experiment with the extractvalue.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Geert GOracle dbaCommented:
and again ... why do you put /*+ parallel */ in every query ???

what is the point of doing that on dba_tables ???
Alexander Eßer [Alex140181]Software DeveloperCommented:
what is the point of doing that on dba_tables ???
Apart from "good looking"?! Nothing (in that case)!
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

johnsoneSenior Oracle DBACommented:
The parallel hint isn't on DBA_TABLES, it is on the count of the table in the sub-query.  You are trying to get a count of the rows in every table in a schema.

The real question is how exact does that have to be?  Stats should get you pretty close with:

SELECT table_name, 
FROM   dba_tables 
WHERE  owner = '&SCHEMA_NAME'; 

Open in new window

Alexander Eßer [Alex140181]Software DeveloperCommented:
Stats should get you pretty close with
It depends: take staging or temp tables for instance -> some of those may get truncated at some point in processing. Stats will show then, let's say 125345 rows, whereas the table is empty!!
Sure, in many/most cases, you can rely on stats, but you should keep in mind that this can be very vague in some cases!
johnsoneSenior Oracle DBACommented:
True temp tables would always have no rows in a count.  You can only see temp tables that are part of your session.

I wouldn't think you would care about the counts in staging tables.  They are transient.  The number of rows in the table really isn't meaningful.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.