oracle 查询每个用户下的表行数

来源:互联网 发布:ios国外福利软件 编辑:程序博客网 时间:2024/06/16 04:58

--查询每个用户下表的行数
SET serveroutput ON;
DECLARE
  i VARCHAR(200);
  v_sql VARCHAR(2000);
  t_owner VARCHAR(200);
  t_count number;
  CURSOR v_owners
  IS
    SELECT owner||'.'||table_name aa FROM dba_tables where tablespace_name not in ('SYSAUX','SYSTEM') and iot_name is null;--去掉系统表和iot
BEGIN
  for i in v_owners loop
  v_sql:='select count(*) from '|| i.aa;
  execute immediate v_sql into t_count;
  dbms_output.put_line(i.aa||'='||t_count);
  end loop;
END;


--统计每个用户下有多少张表


SET serveroutput ON;
DECLARE
  i VARCHAR(200);
  v_sql VARCHAR(2000);
  t_owner VARCHAR(200);
  t_count number;
  CURSOR v_owners
  IS
    SELECT DISTINCT owner FROM dba_tables;
BEGIN
  for i in v_owners loop
  dbms_output.put_line(i.owner);
  v_sql:='select count(*) from dba_tables where owner='||q'(')'||i.owner||q'(')';
  execute immediate v_sql into t_count;
  dbms_output.put_line(t_count);
  end loop;
END;


0 0