先不論索引是否被濫用,今天只談雖然建立了索引,但不同的sql語句寫法,用不上的問題
看看下面這顆樹,就知道索引用不了的原因了
aab ad
abc adm
abcd admn
1. not 用不了索引
2. <> 用不了索引
3. 與null值比較用不了索引
4. like , select * from emp where ename like 'luo%' --能用上
select * from emp where ename like '%dai' --不能
5. 查詢字段使用了函式
select * from emp where to_char(reg_date,'yyyy')='2009'
當然,還包括了||連線符,對查詢欄位做運算等,如: where age+1=30
[b] 解決辦法,使用fbi(基於函式的索引)[/b]
6. 多個字段建立組合索引
如對班號,姓名建立索引,並且班號在前
where class_no='200105302' and stu_name= '羅某' --可以用索引
where class_no='200105302' --可以
where stu_name='羅某' --不可以
原因和like類似
7. 注意資料型別隱式轉換的問題
如service_type欄位,資料庫表裡varchar2型別,但是像下面這樣寫
where service_type=82 --用不了,隱式型別轉換
一些sql語句
一。在oracle中建表,怎麼實現id自動編號 1 建表 create table code test id int,name varchar2 20 2.建立序列 create sequence s country id increment by 1 start with 1 maxvalue 9...
一些Sql語句
case when xx then yy else zz 例 case when count is null then 0 else count 當count為空的時候賦值0,不為空則取原值 isnull express1,express2 例 isnull count,0 當count為空的時候則...
一些SQL語句
在工作中收集了一些有用的語句 加密 解密 declare clearpwd varchar 255 declare encryptedpwd varbinary 255 select clearpwd test select encryptedpwd convert varbinary 255 pw...