我的目标是使用 PL/SQL 在 Oracle 中编写一个脚本,以从以下格式的数据库表中获取数据。
table_name|table_size|avg_row_length
我需要数据库中所有可用的表。以下是尝试编写以获取特定架构的上述详细信息的脚本。但是我得到以下错误
PLS-00103:在预期以下情况之一时遇到符号“AVG_ROW_SIZE”::=; 不为空默认字符
SET serveroutput on;
clear screen;
set lin 20000;
set trimspool on;
set feed off;
set verify off;
set head off;
spool &&1..metadata_report.out
DECLARE
v_tbl_name VARCHAR2(1500);
v_row_num NUMBER(20);
table_size NUMBER(20);
avg_row_size NUMBER(30);
CURSOR c1 IS
SELECT DISTINCT table_name
FROM all_tables
WHERE owner = Upper('&&1')
ORDER BY table_name ASC;
c1_rec c1%ROWTYPE;
BEGIN
OPEN c1;
LOOP
FETCH c1 INTO c1_rec;
exit WHEN c1%NOTFOUND;
EXECUTE IMMEDIATE
'select sum((bytes/1024)) from user_extents where segment_name = "'||c1_rec.table_name||'"' INTO
table_size;
EXECUTE IMMEDIATE
'select decode(count(*),NULL,0, count(*)) FROM &&1.."'||c1_rec.table_name||'"'
INTO v_row_num;
IF( v_row_num = 0 ) THEN
avg_row_size := 0;
ELSE
EXECUTE IMMEDIATE 'SELECT table_size/v_row_num FROM DUAL' INTO avg_row_size;
END IF;
dbms_output.Put_line(c1_rec.table_name
||'|'
||table_size
||'|'
||avg_row_size);
END LOOP;
CLOSE c1;
END;
/