查詢語句pl/sql中用F5優化語句
ORACLE的explain plan工具的作用只有一個,獲取語句的執行計划
1.語句本身並不執行,ORACLE根據優化器產生理論上的執行計划
2.語句的分析結果存放在表PLAN TABLE中
select * from TABLE
where NOWTIME >=to_date('20160101','yyyy-mm-dd') and NOWTIME < to_date('20160102','yyyy-mm-dd')
通過截圖顯示select語句是走索引的“INDEXRANGE SCAN”后邊是索引名稱,cost顯示成本,走索引成本是很低的。
如果沒有“INDEXRANGE SCAN”,表之前是建有索引,說明索引失效,我們無需刪掉再建立索引,只需要用以下語句重建索引,速度很快,即使表里有上千萬數據。
alter index index_name rebuild tablespace tablespace_name 加入表空間名,會將指定的索引移動到指定的表空間當中。
存儲過程:
//////////////////////////////////////////
create or replace procedure loop_while
(
start_date in date,
end_date in date
)
is
current_date_str date := start_date;
current_date_str_end date;
begin
while current_date_str <=end_date
loop
current_date_str_end:=current_date_str+1;
insert into TABLE1
select * from TABLE
where NOWTIME >=current_date_str and NOWTIME < current_date_str+1 ;
commit;
current_date_str:=current_date_str+1;
end loop;
end loop_while;
/////////////////////////////////////////////////////////////////
current_date是關鍵字,只會獲取當前日期
sysdate取的是服務器(主機)的當前日期和時間
current_date取得是會話的當前日期和時間
注意:一般情況下,二者相同。但如果修改了當前會話的時區,則會不同。
按天循環插入表中。