以下需求,如何查询?

javakernel 2011-06-10 09:43:53
(1)从数据库中查询出所有开头为Info的表
(2)然后计算出每个Info表的总记录数
(3)最后需要的结果集是表名和对应得总记录数

数据库为Oracle,请问sql如何写?
...全文
97 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
tangren 2011-06-10
  • 打赏
  • 举报
回复
--调用收集统计数据的包
execute dbms_stats.gather_schema_stats(user);
--然后再
select t.table_name,t.num_rows from USR_tables t where t.table_name like 'INFO%'
javakernel 2011-06-10
  • 打赏
  • 举报
回复
用PLSQL 怎么写啊
javakernel 2011-06-10
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 liubei611 的回复:]

--当前用户的表
select t.table_name,t.num_rows from USR_tables t
where t.table_name like 'INFO%'
--所有自定义用户表
select t.table_name,t.num_rows from all_tables t
where t.table_name like 'INFO%'
--整个库的表
se……
[/Quote]老兵新手说的对,我在考虑得到表名的结果集后,是否得用游标进行处理,然后用select count(*) from table的方式得到每张表的记录数。
javakernel 2011-06-10
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 sad_hopedream 的回复:]

(2)
select count(*) cnt from table
[/Quote]用user_tables表中的num_rows字段得到的数据,跟表中实际的记录数不一样啊
tangren 2011-06-10
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 sad_hopedream 的回复:]

(3)
select t.table_name,t.num_rows from user_tables t
where t.table_name like 'info%'
[/Quote]

这个不是实时的数据,除非你重新收集统计数据,然后再执行
exec dbms_stats.gather_schema_stats(user);
liubei611 2011-06-10
  • 打赏
  • 举报
回复
--当前用户的表
select t.table_name,t.num_rows from USR_tables t
where t.table_name like 'INFO%'
--所有自定义用户表
select t.table_name,t.num_rows from all_tables t
where t.table_name like 'INFO%'
--整个库的表
select t.table_name,t.num_rows from DBA_tables t
where t.table_name like 'INFO%'
sad_hopedream 2011-06-10
  • 打赏
  • 举报
回复
(3)
select t.table_name,t.num_rows from user_tables t
where t.table_name like 'info%'
sad_hopedream 2011-06-10
  • 打赏
  • 举报
回复
(2)
select count(*) cnt from table
sad_hopedream 2011-06-10
  • 打赏
  • 举报
回复
(1)
select * from user_tables t
where t.table_name like '%info%'
sad_hopedream 2011-06-10
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 tangren 的回复:]
引用 3 楼 sad_hopedream 的回复:

(3)
select t.table_name,t.num_rows from user_tables t
where t.table_name like 'info%'


这个不是实时的数据,除非你重新收集统计数据,然后再执行
exec dbms_stats.gather_schema_stats(user);
[/Quote]
学习了

17,086

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧