mybatis 中模糊查询 like

1.  like '%${classes.text}%'  

 在Oracle  MySQL中均可使用,且查询正确。亲测可行

2.   like '%' || #{classes.text} || '%'

在Oracle中可以使用,且查询正确,但是在mysql中,报错,有乱码,不知道什么原因,未解决,随后补充。

以下是错误信息:

Translating SQLException with SQL state '42000', error code '1064', message [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' 
    
     and text like '%' || '山东' || '%' 
    
   ) c' at line 9]; SQL was [] for task [
### Error querying database.  Cause: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' 
     and text like '%' || '山东' || '%' 
    
   ) c' at line 9

 

3   like CONCAT('%',#{classes.text},'%') 

使用情况 同2.

posted @ 2017-05-27 10:14  弗兰克中校  阅读(604)  评论(0编辑  收藏  举报