SQLDeveloper:查找数据库中的总行数?

时间:2021-03-04 01:01:35

Within my database I would like to know the total amount of rows.

在我的数据库中,我想知道总行数。

I am able to find out the amount of rows in a certain table in my database with this query:

我可以使用此查询找出数据库中某个表中的行数:

select count (*) From TABLE_NAME;

However, is there a more efficient way, rather than repeating this for every table?

但是,有没有更有效的方法,而不是为每个表重复这个?

1 个解决方案

#1


0  

You may use this pl/sql block to know the total no of rows in all tables.

您可以使用此pl / sql块来了解所有表中的总行数。

DECLARE  
   t_name VARCHAR2(100);  
   total_rows NUMBER;  
   t_count NUMBER;  
BEGIN  
  total_rows := 0;  
  t_count := 0;  

  FOR rec IN (SELECT table_name FROM user_tables)  
  LOOP  
    EXECUTE IMMEDIATE 'select count(1) from '||rec.table_name  
    INTO t_count;  

    total_rows := total_rows + t_count;  
  END LOOP;  

  dbms_output.put_line('Total no of Rows: '||total_rows);  
EXCEPTION  
  WHEN OTHERS THEN  
    dbms_output.put_line(SQLERRM);  
END;     

#1


0  

You may use this pl/sql block to know the total no of rows in all tables.

您可以使用此pl / sql块来了解所有表中的总行数。

DECLARE  
   t_name VARCHAR2(100);  
   total_rows NUMBER;  
   t_count NUMBER;  
BEGIN  
  total_rows := 0;  
  t_count := 0;  

  FOR rec IN (SELECT table_name FROM user_tables)  
  LOOP  
    EXECUTE IMMEDIATE 'select count(1) from '||rec.table_name  
    INTO t_count;  

    total_rows := total_rows + t_count;  
  END LOOP;  

  dbms_output.put_line('Total no of Rows: '||total_rows);  
EXCEPTION  
  WHEN OTHERS THEN  
    dbms_output.put_line(SQLERRM);  
END;