子查询里有rownum函数时
来源:互联网 发布:淘宝灯具安装联盟 编辑:程序博客网 时间:2024/04/28 09:29
select * from t1 where object_id in (select object_id from t2 where t1.object_id=t2.object_id and rownum<10);create table t1 as select * from dba_objectscreate table t2 as select * from dba_objects子查询返回1行还是100行,都没有意义SQL> select * from t1 where object_id in (select object_id from t2 where t1.object_id=t2.object_id and rownum<10);已选择9行。执行计划----------------------------------------------------------Plan hash value: 4165492305-----------------------------------------------------------------------------| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |-----------------------------------------------------------------------------| 0 | SELECT STATEMENT | | 32 | 6624 | 4736 (1)| 00:00:57 ||* 1 | FILTER | | | | | || 2 | TABLE ACCESS FULL | T1 | 72109 | 14M|228 (1)| 00:00:03 ||* 3 | FILTER | | | | | ||* 4 | COUNT STOPKEY | | | | | ||* 5 | TABLE ACCESS FULL| T2 | 1 | 13 | 2 (0)| 00:00:01 |-----------------------------------------------------------------------------Predicate Information (identified by operation id):--------------------------------------------------- 1 - filter( EXISTS (<not feasible>) 3 - filter("OBJECT_ID"=:B1) 4 - filter(ROWNUM<10) 5 - filter("T2"."OBJECT_ID"=:B1)这里T1表的OBJECT_ID 传入到子查询中,子查询里限制条数毫无意思等价于select * from t1 where object_id in (select object_id from t2 where t1.object_id=t2.object_id );测试;SQL> select count(t2.object_id) from t2 ,t1 where t1.object_id=t2.object_id and t2.object_id=3;COUNT(T2.OBJECT_ID)-------------------512SQL> select object_id from t1 where object_id=3; OBJECT_ID---------- 3档T1把OBJECT_ID=3 传入到子查询时,那么子查询会返回512行相当于:select* from t1 where object_id in (select object_id from t2 where object_id=3);select * from t1 where object_id in (3,3,3,3,3,3,3,3,3................);512个这个和select * from t1 where object_id in (3)没有任何区别:这个子查询加rownum 除了阻止子查询展开外,没有任何意思。
0 0
- 子查询里有rownum函数时
- 【SQL】子查询中有rownum,导致全表扫描,效率极
- 行号rownum问题,以及相关子查询
- 数据库 day60,61 Oracle入门,单行函数,多表查询,子查询,事物处理,约束,rownum分页,视图,序列,索引
- Oracle基本操作六:子查询,rownum,rowid
- Mysql里的子查询
- 嵌套子查询里面有树形查询
- oracle 里rownum详解
- 聚合函数查询、连接查询、子查询
- rownum分页查询
- rownum进行分页查询
- mysql类似rownum查询
- 查询数据库里是否有重复值
- 子串查询函数strstr
- 2、row_number函数+子查询
- sql --- 子查询+分组函数
- 函数查询所有子节点
- sql 2005 rownum用法以及带order by 子查询的用法
- uva 705 Slash Maze
- poj3692二分图最大团
- 1037. Magic Coupon (25)
- Android之旅十五 android中的网络操作
- Codeforce 453 C. Little Pony and Summer Sun Celebration
- 子查询里有rownum函数时
- Effective C++读书笔记之九:绝不在构造和析构过程中调用virtual
- 文档 ID 359515.1
- java学习123之static
- 清和月
- RCP项目导出exe 步骤
- asp.net MVC 安全性
- 结构体指针内存——指针数组——字符串指针内存申请
- vs2010 命令行参数的简单写法