SQL SELECT LIKE (Insensitive casing)

后端 未结 9 1781
野性不改
野性不改 2021-02-02 05:32

I am trying to execute the sql query:

select * from table where column like \'%value%\';

But the data is saved as \'Value\' ( V is capital ).

相关标签:
9条回答
  • 2021-02-02 06:15

    use LOWER Function in both (column and search word(s)). Doing it so, you assure that the even if in the query is something like %VaLuE%, it wont matter

    select qt.*
    from query_table qt
    where LOWER(column_name) LIKE LOWER('%vAlUe%');
    
    0 讨论(0)
  • 2021-02-02 06:17

    I know this is a very old question, but I'm posting this for posterity:
    Non-binary string comparisons (including LIKE) are case-insensitive by default in MySql: https://dev.mysql.com/doc/refman/en/case-sensitivity.html

    0 讨论(0)
  • 2021-02-02 06:17

    This will eventually do the same thing. The ILIKE works, irrespective of the casing nature

    SELECT * FROM table WHERE column_name ILIKE "%value%"

    0 讨论(0)
  • 2021-02-02 06:25

    If you are using PostgreSQL, a simpler solution is to use insensitive like (ILIKE):

    SELECT * FROM table WHERE column ILIKE '%value%'
    
    0 讨论(0)
  • 2021-02-02 06:25

    you should use either lower or upper function to ignore the case while you are searching for some field using like.

    select * from student where upper(sname) like 'S%';
    

    OR

    select * from student where lower(sname) like 'S%';
    
    0 讨论(0)
  • 2021-02-02 06:28

    Either use a case-insensitive collation on your table, or force the values to be lower case, e.g.

    WHERE lower(column) LIKE lower('%value%');
    
    0 讨论(0)
提交回复
热议问题