Home  >  Article  >  Database  >  How to query the number of data items in Oracle

How to query the number of data items in Oracle

WBOY
WBOYOriginal
2022-01-26 14:23:1222523browse

In Oracle, you can use the SELECT statement to query the number of data. This statement is used for simple data query. The syntax is "SELECT sum(num_rows) FROM user_tables;".

How to query the number of data items in Oracle

The operating environment of this tutorial: Windows 10 system, Oracle 11g version, Dell G3 computer.

How to query the number of data in Oracle

Statistics in the system table:

SELECT sum(num_rows) FROM user_tables;

Result:

How to query the number of data items in Oracle

Example:

How to query the number of data items in Oracle

There is another way to write stored procedure statistics

The example is as follows:

declare
v_tName varchar(50);
v_sqlanalyze varchar(500);
v_num number;
v_sql varchar(500);
cursor c1 
is
select table_name from user_tables;
begin
open c1;
loop
fetch c1 into v_tName;
if c1%found then
 
v_sqlanalyze :='analyze table  '||v_tName||'  estimate statistics';
execute immediate v_sqlanalyze;
v_sql := 'select NUM_ROWS  from user_tables where table_name =upper('''||v_tName||''')';
 
execute immediate v_sql into  v_num;
dbms_output.put_line('表名: '||v_tName||' 行数: '||v_num);
else
exit;
end if;
end loop;
end;

Recommended tutorial:《Oracle Video Tutorial

The above is the detailed content of How to query the number of data items in Oracle. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn