命令获取oracle所有表的元数据?

时间:2016-06-16 22:48:18

标签: oracle oracle11g oracle-sqldeveloper

任何人都可以帮我使用SQL Developer命令来获取有关表中行数,每个表中列数以及特定模式的每个表的当前更新日期的信息吗?

1 个答案:

答案 0 :(得分:2)

获取架构TEST的每个表的行数和最新SCN的日期:

CREATE TYPE TEST.stringlist IS TABLE OF VARCHAR2(4000);
/

VARIABLE cur REFCURSOR;

DECLARE
  t_sql TEST.stringlist;
  v_sql CLOB;
  v_scn NUMBER;
  v_owner VARCHAR2(30) := 'TEST';
BEGIN
  SELECT MIN(SCN)
  INTO   v_scn
  FROM   sys.smon_scn_time;

  SELECT 'SELECT ''' || TABLE_NAME || ''' AS table_name, '
                 || 'TRUNC( MAX( CASE WHEN ORA_ROWSCN >= ' || v_scn || ' THEN SCN_TO_TIMESTAMP( ORA_ROWSCN ) END ) ) AS last_update_day, '
                 || 'COUNT(*) AS num_rows '
         || 'FROM ' || v_owner || '.' || table_name
  BULK COLLECT INTO t_sql
  FROM   ALL_TABLES
  WHERE  OWNER = v_owner;

  v_sql := t_sql(1);
  FOR i IN 2 .. t_sql.COUNT LOOP
    v_sql := v_sql || ' UNION ALL ' || t_sql(i);
  END LOOP;

  OPEN :cur FOR v_sql;  
END;
/

PRINT cur;

获取架构TEST的每个表的列数:

SELECT TABLE_NAME,
       COUNT(*) AS num_columns
FROM   ALL_TAB_COLUMNS
WHERE  OWNER = 'TEST'
GROUP BY TABLE_NAME;