查询Oracle数据库中各个表的实际记录数

时间:2023-01-14 13:57:38
DECLARE
  CURSOR tab_cursor IS SELECT table_name FROM user_tables;
  v_table_name user_tables.table_name%type;
  v_num number;
  v_p1 number;
BEGIN
  open tab_cursor;
  loop
     fetch tab_cursor into v_table_name;
     exit when tab_cursor%notfound;
     execute immediate 'select count(*) from ' || v_table_name into v_num;
     dbms_output.put_line(v_table_name || ' : ' || to_char(v_num));
   end loop;
  CLOSE tab_cursor;
END;