为什么select * from 表名 where 字段名 like ‘%’ ? ‘%’;
%与?之间必须要加空格才能实现模糊查询 而不加就不行 这个空格有什么作用 或者存在什么机制吗

解决方案 »

  1.   

    [SQL]select * from `user` where email like '%' 12 '%'[Err] 1064 - 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 '12 '%'' at line 1
    我这么写不行啊
      

  2.   

    在dbms里面中间的值用单引号包起来 中间加空格就可以 jdbc里面用预执行对象通过占位符传递  中间加空格也可以
      

  3.   

    噢喔,中间也加单引号啊;
    我找到了这些但是没有更具体的解释,你可以再百度搜搜;
    https://www.cnblogs.com/end/archive/2011/04/01/2002516.html
    https://blog.csdn.net/weixin_34220179/article/details/92683444
      

  4.   

    试了一下,select * from `user` where `password`='12''3''4'可以查到password=12'3'4的
      

  5.   

    用concat函数连接会肯稳妥些
      

  6.   

    不需要加空格呀,你那种写法可以执行?
    参考:
    mysql写法:(双引号、单引号都行)
    select * from user where email like "%12%";SQL Server写法:(只能单引号)
    select * from user where email like '%12%';