任何人都可以帮我使用SQL Developer命令来获取有关表中行数,每个表中列数以及特定模式的每个表的当前更新日期的信息吗?
答案 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;