gpt4 book ai didi

database - 数数来自多个表的记录;甲骨文数据库

转载 作者:搜寻专家 更新时间:2023-10-30 19:46:40 26 4
gpt4 key购买 nike

我知道我需要使用此查询来获取架构的表列表:从 all_tables 中选择 table_name,其中 owner='schema'

我知道以下查询计算表中的记录:从 schema.table 中选择 count(*)

该架构中有 2400 多个表。我的问题是如何一步算出所有表的记录数?

最佳答案

您可以使用 DBMS_XMLGEN.GETXMLTYPE 函数一次完成此操作:

SQL> select table_name
2 , to_number
3 ( extractvalue
4 ( dbms_xmlgen.getxmltype('select count(*) c from ' || table_name)
5 , '/ROWSET/ROW/C'
6 )
7 ) cnt
8 from user_tables
9 order by table_name
10 /

TABLE_NAME CNT
------------------------------ ----------
... [output removed] ...

71 rows selected.

但是如果您的模式包含大量数据,这可能需要很长时间。如果估计也没有问题,只需选择 NUM_ROWS 就足够了。

问候,
罗布。

关于database - 数数来自多个表的记录;甲骨文数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6703444/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com