Oracle statistics the number of rows for all tables under specified conditions

Source: Internet
Author: User

Today we need to count the number of rows for all the tables under the specified user, and then use the Oracle built-in view:

Select Table_name,num_rows from dba_tables where owner = ' USERNAME '; or select Table_name,num_rows from User_all_tables;

However, the statistical results found that some of the statistics of the table and the actual number of differences, and therefore, directly wrote a statistic to specify the conditions of the table Records of SQL:

--Create a table to store the calculated results Create table t_temp (T_NAME VARCHAR2 (), t_number number);--Calculate the number of rows for all tables, and save Declaretable_numbers number;i number;table_name1 varchar2 (;cursor cursor_value ) IS SELECT TABLE_NAME FROM USER_ALL_TABLES WHERE INSTR (table_name, ' $ ', 1) =0  AND INSTR (table_name, ' smid_ ', 1) =0;begin   open cursor_value;        loop         fetch cursor_value into  table_name1;             execute  immediate  ' Select count (*)  from  ' | | table_name1 into table_numbers;            Dbms_output. Put_Line (table_name1| | '       ' | | Table_numbers);             insert into t _temp VALUES (table_name1,table_numbers);           commit;            exit when cursor_value%notfound;            end loop;    close  cursor_value;   end;    --query statistics, the result is the ideal result select *from t_temp ;


Oracle statistics the number of rows for all tables under specified conditions

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.