这几天做性能优化,网上找了些资料。

有时候需要导出某用户下的所有table、view、sequence、trigger等信息,下面的SQL可以将这些信息select出来:

  1. select * from user_tables; 
  2.  
  3. select * from user_views; 
  4.  
  5. select * from user_sequences; 
  6.  
  7. select * from user_triggers; 

想查找表的数据条数

试试这个

  1. select t.table_name,t.num_rows from user_tables t 

如果没有值,那就创建个函数

代码

  1. create or replace function count_rows(table_name in varchar2, 
  2.  
  3.   owner in varchar2 default null
  4.  
  5.   return number 
  6.  
  7.   authid current_user 
  8.  
  9.   IS 
  10.  
  11.   num_rows number; 
  12.  
  13.   stmt varchar2(2000); 
  14.  
  15.   begin 
  16.  
  17.   if owner is null then 
  18.  
  19.   stmt := 'select count(*) from "'||table_name||'"'
  20.  
  21.   else 
  22.  
  23.   stmt := 'select count(*) from "'||owner||'"."'||table_name||'"'
  24.  
  25.   end if
  26.  
  27.   execute immediate stmt into num_rows; 
  28.  
  29.   return num_rows; 
  30.  
  31.   end 

再执行查询

  1. select table_name, count_rows(table_name) nrows from user_tables