oracle怎么条件强制走索引,如何让oracle的select强制走索引

大多数情况下,oracle数据库内置的查询优化策略还是很成功的,但偶尔也有犯2的时候,即使有索引,也会做全表扫描,可以参考以下语句的写法,强制让select语句使用索引

CREATE OR REPLACE VIEW V_RES_CBA AS

SELECT /*+INDEX(SEG IDX_T_RES_ALLOSEG_ALLOID)*/

ALLO.ALLOID AS RESID,

NULL AS AWB,

ALLO.ALLOTMENT AS ALLO_ID,

DAYS.FDATE + NVL(SEG.DAYSDISP, 0) AS FDATE,

ALLO.SPECULD AS SPECULD

FROM T_RES_ALLO ALLO, T_RES_ALLOSEG SEG, V_FDATE DAYS

WHERE ALLO.ALLOID = SEG.ALLOID

AND ((ALLO.ALLOIND = 'A' AND ALLO.ALLO_DATE = DAYS.FDATE) OR

(ALLO.ALLOIND = 'S' AND

NVL(ALLO.SDATE, ALLO.ALLO_DATE) = DAYS.FDATE))

UNION

SELECT /*+INDEX(SEG IDX_T_RES_ALLOSEG_ALLOID)*/

ALLO.ALLOID AS RESID,

NULL AS AWB,

ALLO.ALLOTMENT AS ALLO_ID,

DAYS.FDATE + NVL(SEG.DAYSDISP, 0) AS FDATE,

ALLO.SPECULD AS SPECULD<

你可能感兴趣的:(oracle怎么条件强制走索引)