数据库: mysql + brighthouse在表里有 一个值是   \a"/
查找所有以  \a 开头的数据, 我用  where tac like "\\a%"     为什么查不到数据请教这个like 语句该怎么写谢谢。

解决方案 »

  1.   


    select * from mytable where tac like '\\\\a%';
      

  2.   

    select * from tb where left(tac)= '\\a';
      

  3.   

    发现原因了,必须四个斜杠,
    where tac like "\\\\a%"
    这样就需要对前台传过来的字符串 "\a%" 进行2次 addslashes,比如要找等于 \a"/  的:where tac = "\\a\"\/";   这里只用 addslashes 一次
    要找以 \a 开头的: where tac like "\\\\a%";      这里需要2次 addslashes拼where语句时候怎么知道需要用几次 addslashes
      

  4.   

    正则表达式的地方就要用四个反斜线表示一个反斜线,like应该是当成正则表达式来对待的。
      

  5.   

    select * from tb where left(tac,2)= '\\a';
      

  6.   

    这咋整。。通配符可能出现在任何位置,不一定是从左边开始like,left貌似不行
      

  7.   

    select * from tb  where locate('\\a',tac)>0;
      

  8.   

    mysql> select '\\abcd' like '\\\\a%';
    +------------------------+
    | '\\abcd' like '\\\\a%' |
    +------------------------+
    |                      1 |
    +------------------------+
    1 row in set (0.00 sec)mysql>
      

  9.   

    这个不像like能判断 以xx起始或结束或在中间,只能判断是否出现