String sql = “select * from emp where empno in (select a.empno from (select rownum,e.* from emp e) a where rownum<=10)”;
上面sql的查询原理:红色标记部分为子查询部分,sql先执行子查询部分,得到一个结果集(10条),然后在执行外部查询,在执行外部查询的时候,要和子查询的结果集比较10次,
使用with as:
with ss as (select a.empno from (select rownum,e.* from emp e) a where rownum<=10)
select * from emp where empno in (select * from ss)
1、如果WITH AS短语所定义的表名被调用两次以上,则优化器会自动将WITH AS短语所获取的数据放入一个TEMP表里,如果只是被调用一次,则不会
2、如果一个sql经常被调用,一般用with as实现