2008-7-3 22:05
joyangleyang
请教这个嵌套查询这么写
各位好:我记得好像在sqlplus中有这样的功能,就是我一个语句返回多个表名,然后这个表名就是后一个语句的要查询的表,执行的时候自动会返回多条记录。
例如:
select count(*) from '(select table_name from user_tables where rownum<5)'
我就是想得到指定的4张表的记录数。而这个4张表的表名是我通过一个条件得到的。具体不知道怎么写了,请大侠指点,谢了!
2008-7-3 22:35
谁
不知道有没有那种方法
我用一种笨办法实现的
1/执行
select 'select count(*) from ' || table_name || ';' from user_tables where rownum<5;
2/复制得到的4条sql语句,粘贴执行即可
2008-7-3 22:58
cosio
把四张表用union all 连起来,在用sum加起来!
select sum(a) from
(
select a from a
union all
select b from b
union all
select c from c
union all
select d from d
)
2008-7-4 08:11
jvkojvko
使用动态sql
2008-7-4 08:40
gerard
为什么说是"在sqlplus中有这样的功能"?
2008-7-4 10:41
mychary
[quote]原帖由 [i]joyangleyang[/i] 于 2008-7-3 22:05 发表 [url=http://www.itpub.net/redirect.php?goto=findpost&pid=10847608&ptid=1016312][img]http://www.itpub.net/images/common/back.gif[/img][/url]
各位好:我记得好像在sqlplus中有这样的功能,就是我一个语句返回多个表名,然后这个表名就是后一个语句的要查询的表,执行的时候自动会返回多条记录。
例如:
select count(*) from '(select table_name from user_tables where rownum [/quote]
就功能上说,user_tables 中num_rows 就是你要的(如果表分析了)
2008-7-6 12:13
joyangleyang
我想要这样的结果:在sqlplus下生成执行语句然后自动运行该语句。例如
select 'select count(*) from ' || table_name || ';' from user_tables where rownum<5;
会产生4条结果
select count(*) from a;
select count(*) from b;
select count(*) from c;
select count(*) from d;
然后能自动运行这四条语句产生结果,谢谢了!
页:
[1]

Powered by ITPUB论坛