mysql 安全模糊搜索 不用like,sql语句怎么写

解决方案 »

  1.   

    regexp
      

  2.   

    where instr(col,'中国')
      

  3.   

    instr、REGEXP,速度不会快
      

  4.   

    mysql> select * from tb;
    +------+---------+-----------+-------------+------------+
    | id   | project | yearmonth | weekormonth | weekmonths |
    +------+---------+-----------+-------------+------------+
    |    1 | A       | 201306    | 第一周   |          1 |
    |    2 | A       | 201306    | 第二周   |          2 |
    |    3 | B       | 201306    | 第一周   |          1 |
    |    4 | NULL    | NULL      | NULL        |       NULL |
    +------+---------+-----------+-------------+------------+
    4 rows in set (0.00 sec)mysql> select * from tb where instr(project,'B');
    +------+---------+-----------+-------------+------------+
    | id   | project | yearmonth | weekormonth | weekmonths |
    +------+---------+-----------+-------------+------------+
    |    3 | B       | 201306    | 第一周   |          1 |
    +------+---------+-----------+-------------+------------+
    1 row in set (0.00 sec)
      

  5.   

    instr() regexp
      

  6.   

    正则表达式regexp
      

  7.   

    你的ini文件中可以设置支持中文的,默认是支持的。
      

  8.   

    数据量大的时候,考虑使用sphinx等