I just wanted to know how do I can I find the number of rows in a certain table.
CodePudding user response:
Use the COUNT
aggregation function:
SELECT COUNT(*) FROM table_name;
CodePudding user response:
Apart from the obvious count
function, if you regularly gather schema statistics, you can - at least approximately (if tables' contents change relatively frequently) - query user_tables
and check the num_rows
column's contents:
SQL> exec dbms_stats.gather_schema_stats('SCOTT');
PL/SQL procedure successfully completed.
SQL> select table_name, num_rows from user_tables;
TABLE_NAME NUM_ROWS
-------------------- ----------
EMP 14
DEPT 4
BONUS 0
SALGRADE 5
INVOICE 4
ERRORS 110
DAT 0
<snip>
Is that really so? For example:
SQL> select count(*) from emp;
COUNT(*)
----------
14
SQL> select count(*) from dept;
COUNT(*)
----------
4
SQL> select count(*) from bonus;
COUNT(*)
----------
0
SQL> select count(*) from errors;
COUNT(*)
----------
110
SQL>