Mybatis中模糊查詢的各種寫法
阿新 • • 發佈:2019-01-04
工作中用到,寫三種用法吧,第四種為大小寫匹配查詢
1. sql中字串拼接
SELECT * FROM tableName WHERE name LIKE CONCAT(CONCAT('%', #{text}), '%');
2. 使用 ${...} 代替 #{...}
SELECT * FROM tableName WHERE name LIKE '%${text}%';
3. 程式中拼接
Java
// String searchText = "%" + text + "%";
String searchText = new StringBuilder("%").append(text).append("%").toString();
parameterMap.put("text", searchText);
SqlMap.xml
SELECT * FROM tableName WHERE name LIKE #{text};
4. 大小寫匹配查詢
SELECT * FROM TABLENAME WHERE UPPER(SUBSYSTEM) LIKE '%' || UPPER('jz') || '%'
或者
SELECT * FROM TABLENAME WHERE LOWER(SUBSYSTEM) LIKE '%' || LOWER('jz') || '%'