oracle 分頁查詢/快捷建表/自我複製

分頁查詢

 select t2.* from (select t1.*,rownum rn fromselect * from 表名 where 條件) t1 where rn<= 結束行編號) t2 where t1.rn>= 開始行編號;

理解:
第一步:首先將所有行加載到內存,這一步最好不要添加條件,聽韓順平老師的課時他說可以添加條件,自己覺得不太對,猜想本步應該是將所有數據加載到內存中,添加條件時會降低效率,可以先全部加載增加一步添加條件。暫時使用老師講的,後面再做驗證。

select * from 表名 where 條件

第二步:限制結束行編號

select t1.*,rownum rn fromselect * from 表名 where 條件) t1 where rn<= 結束行編號~~~
第三步:限制開始行
~~~sql
 select t2.* from (select t1.*,rownum rn fromselect * from 表名 where 條件) t1 where rn<= 結束行編號) t2 where t1.rn>= 開始行編號 ;

快捷建表/複製表結構與數據

create table 表名 as select 列名1,列名2... from  表名;

自我複製
當需要對某個sql語句進行效率測試,可使用該方法產生大量數據。

insert into1 (列名1,列名2...values ( select 列名1,列名2... from1)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章