Oracle架构表行数

Oracle:11g操作系统:Linux

我有这个非常棘手的问题,我正在试图解决,但不能得到明确的答案…我search谷歌…等,但没有运气与我的要求…

模式统计是不可靠的,所以想要查询dba_tables ..也不想在数据库下创build任何程序或function..只是试图用简单的SQL来实现。

问:如何后台处理特定模式的所有表行数并显示table_name?

答:我可以很容易地在spool中显示计数,但不能在计数旁边得到表名。

例如

Table_Name Count tab1 200 tab2 500 tab3 300 

与下面我可以得到计数,但无法找出table_name显示结果…

 spool runme.sql select 'select count(*) from '|| owner || '.' || table_name || ';' from dba_tables where owner = 'user1' order by table_name; spool off 

你可以使用这样的函数,但是它会很慢:

 create or replace function get_rows( p_tname in varchar2 ) return number as l_columnValue number default NULL; begin execute immediate 'select count(*) from ' || p_tname INTO l_columnValue; return l_columnValue; end; / select user, table_name, get_rows( user||'.'||table_name) cnt from user_tables / 

Tom Kyte网站上的这个答案的代码:

http://asktom.oracle.com/pls/asktom/f?p=100:11:::::P11_QUESTION_ID:1660875645686

没有函数调用也是可能的:

 select table_name, to_number( extractvalue( xmltype( dbms_xmlgen.getxml('select count(*) c from '||table_name)) ,'/ROWSET/ROW/C')) count from user_tables; 

从这里提示:

http://laurentschneider.com/wordpress/2007/04/how-do-i-store-the-counts-of-all-tables.html