大多數情況下,oracle資料庫內建的查詢優化策略還是很成功的,但偶爾也有犯2的時候,即使有索引,也會做全表掃瞄,可以參考以下語句的寫法,強制讓select語句使用索引
1create
orreplace
view v_res_cba as
2select
/*+index(seg idx_t_res_alloseg_alloid)
*/3 allo.alloid as
resid,
4null
as awb,
5 allo.allotment as allo_id,
6 days.fdate + nvl(seg.daysdisp, 0) as fdate,
7 allo.speculd as speculd
8from
t_res_allo allo, t_res_alloseg seg, v_fdate days
9where allo.alloid =
seg.alloid
10and ((allo.alloind ='a
'and allo.allo_date = days.fdate) or
11 (allo.alloind ='s
'and
12 nvl(allo.sdate, allo.allo_date) = days.fdate))
13union
14select
/*+index(seg idx_t_res_alloseg_alloid)
*/15 allo.alloid as
resid,
16null
as awb,
17 allo.allotment as allo_id,
18 days.fdate + nvl(seg.daysdisp, 0) as fdate,
19 allo.speculd as speculd
20from
t_res_allo allo, t_res_alloseg seg, v_fdate days
21where allo.alloid =
seg.alloid
22and allo.allo_date is
null
23and allo.alloind ='a
'24and (days.fdate >= allo.sdate and days.fdate <= allo.edate and
25 instr(allo.weekday, days.weekday) >
0) 26
andnot
exists (select
subquery.alloid
27from
t_res_allo subquery
28where subquery.allo_date =
days.fdate
29and subquery.allotment =
allo.allotment)
30 ;
要點:1、/*+index(seg idx_t_res_alloseg_alloid)*/ 這裡的/*...*/中間不要有空格
2、表名要用別名,即:以上面的sql語句為例,要使用seg,而不是t_res_alloseg
如何讓oracle的select強制走索引
大多數情況下,oracle資料庫內建的查詢優化策略還是很成功的,但偶爾也有犯2的時候,即使有索引,也會做全表掃瞄,可以參考以下語句的寫法,強制讓select語句使用索引 1 create orreplace view v res cba as 2select index seg idx t res ...
oracle如何讓表常駐記憶體?
1.前言。如題。2.如何常駐記憶體 摘自 create table 表名 字段 storage buffer pool keep 建表時把表快取到keep中 alter table 表名 storage buffer pool keep 把已存在的表快取至keep中 create table 表名 ...
如何讓plsql連線64位oracle資料庫
plsql只是32位的,如何操作64的資料庫,方法如下 3.然後找到oracle安裝目錄中的network admin tnsnames.ora檔案,將network admin tnsnames.ora資料夾結構及檔案都複製到instantclient basic win32解壓縮的資料夾之中 4...