Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Script to get the table and record count from the database

888081Nov 5 2017 — edited Nov 6 2017

I am trying to write a shell script to get the following details - table name and its count.  I want both displayed in a csv file.  Here is a basic shell script that I started writing.  Need help in completing it.

sqlplus -s / as sysdba <<EOF

set line 200

set pages 2000

set echo off feed off head off verify off

spool count.sql

select 'select count(*) from ' || owner ||'.'||table_name||';' from dba_tables where owner in('TEST','COUNTRY');

spool off

spool count.csv

@count.sql

spool off

exit

EOF

when it runs count.sql script, it prints only the record count.  How do I append the corresponding table name to it ?

Thanks

This post has been answered by Frank Kulash on Nov 5 2017
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 4 2017
Added on Nov 5 2017
2 comments
3,696 views