LIKE BINARY in MySQL

1

I want to select a set of results that, passing the option by like, but the result can be that it is lowercase or capitalized. I did this way:

SELECT * FROM DocumentosAux WHERE numeroDocDisco like binary 'pbra';

Also:

 SELECT * FROM DocumentosAux WHERE binary numeroDocDisco like 'pbra';

But none of the forms gives the desired result, since it could be written as Pbra, pBra, PBRA, etc.

    
asked by Carlos 14.02.2017 в 15:31
source

1 answer

2

You can use:

SELECT *
  FROM DocumentosAux
 WHERE numeroDocDisco COLLATE UTF8_GENERAL_CI like '%pbra%';

(Assuming you are using utf8 as you mention @sstan, otherwise you will have to use the collate corresponding in its version case insensitive _ci )

or

SELECT *
  FROM DocumentosAux
 WHERE lower(numeroDocDisco) like '%pbra%';

On the other hand, if you always want it to be case insensitive, you can change the definition of the table and use COLLATE UTF8_GENERAL_CI .

    
answered by 14.02.2017 / 16:16
source