|
like常用用法: 1.%代表任意數(shù)量的某一或某些字符。 select * from tmp_table t where t.name like '%Bob'(查詢tmp_table表中name列最后三位是BOb的記錄,eg:BBob) select * from tmp_table t where t.name like 'Bob%'(查詢tmp_table表中name列開始三位是BOb的記錄,eg:Bobm) select * from tmp_table t where t.name like '%Bob%'(查詢tmp_table表中name列中包含BOb的記錄,eg:aBObm,aaBobmm) 2._代表某一字符 select * from tmp_table t where t.name like '_Bob'(查詢tmp_table表中name列為四位且最后三位是BOb的記錄,eg:aBob,bBob) select * from tmp_table t where t.name like 'B_ob'(查詢tmp_table表中name列為四位且第二位是任意字符的記錄,eg:Bnob,Bmob) select * from tmp_table t where t.name like 'Bob_'(查詢tmp_table表中name列為四位且最后一位是任意字符的記錄,eg:Bobm,Bobn) regexp_like適用于查詢某一列包含多個(gè)字符串的時(shí)候,常用用法: select * from tmp_table t where regexp_like(t.name,'Bob|Jane|marry' )(查詢tmp_table表中name列中包含Bob或Jane或marry的記錄,eg:Bob Smith,Jane Green) 等同于: select * from tmp_table t where t.name like '%Bob%' or t.name like '%Jane%' or t.name like '%marry%' 這里順便說(shuō)下in、exists的用法: select * from tmp_table t where t.name in('Bob','Jane','marry' ) 等同于 select * from tmp_table t where t.name exists('Bob','Jane','marry' ) 等同于 select * from tmp_table t where t.name ='Bob' or t.name ='Jane' or t.name ='marry' 注:這里“等同于”指的是查詢結(jié)果一樣,并不包括語(yǔ)句的執(zhí)行效率。 |
|
|
來(lái)自: 努力的小美醬 > 《oracle技巧》