當WHERE子句對某一列使用函數時
通常情況下
慶幸的是
大小寫混合情況
在討論由於函數修改了列的內容
SQL> select address from address where upper(name) like
在運行這個查詢語句前
ADDRESS
cleveland
Execution Plan
SELECT STATEMENT
TABLE ACCESS FULL ADDRESS
可以看到
值得慶幸的是
SQL> select address from address where upper(name) like
like
使用這種查詢語句(已設置AUTOTRACE)
ADDRESS
cleveland
Execution Plan
SELECT STATEMENT
CONCATENATION
TABLE ACCESS BY INDEX ROWID ADDRESS
INDEX RANGE SCAN ADDRESS_I
TABLE ACCESS BY INDEX ROWID ADDRESS
INDEX RANGE SCAN ADDRESS_I
現在
在這個例子中
select address from address where
upper(name) like
or name like
得到的結果與以前相同
Execution Plan
SELECT STATEMENT
CONCATENATION
TABLE ACCESS BY INDEX ROWID ADDRESS
INDEX RANGE SCAN ADDRESS_I
TABLE ACCESS BY INDEX ROWID ADDRESS
INDEX RANGE SCAN ADDRESS_I
TABLE ACCESS BY INDEX ROWID ADDRESS
INDEX RANGE SCAN ADDRESS_I
TABLE ACCESS BY INDEX ROWID ADDRESS
INDEX RANGE SCAN ADDRESS_I
如果試圖進一步提高查詢速度
現在讓我們看看
使用REPLACE的情況
正如名字不總是以大寫輸入一樣
如果在列名為 PHONE_NUMBER中搜尋上述號碼時
WHERE replace(replace(phone_number
WHERE子句兩次使用REPLACE 函數去掉了連字符和空格
WHERE replace(replace(phone_number
AND phone_number like
WHERE replace(replace(replace(replace
(phone_number
(phone number like
or phone_number like
該例強調了巧妙地選用WHERE 子句條件的重要性
正確的條件
以後當你遇到包含CHARACTER 數據修改函數列的WHERE 子句時
From:http://tw.wingwit.com/Article/program/Oracle/201311/16757.html