Qual é o sentido do termo LIKE no MySql

5 respostas
G

Qual é o sentido do termo LIKE no MySql?

5 Respostas

maquiavelbona

Comparar termos não numéricos. Traduzindo literalmente seria : como/parece.

– Select * from tabela where campo like ‘texto’
– Selecione * da tabela onde campo parece ‘texto’

Até!

bebad

na pratica seria isso aqui assim oh:

PreparedStatement stmt = this.connection.prepareStatement
("select * from contatos WHERE nome like '%"+nome+"%' order by id");

ResultSet rs = stmt.executeQuery();
S

só pra acrescentar…

  1. select * from teste where nome = ‘%’
  2. select * from teste where nome like ‘%’

no primeiro, o mysql vai retornar somente os registros com o campo nome igual a %, já no segundo, ele vai retornar qualquer coisa, assumindo que ‘%’ é um caractere coringa!

T

ops, duplicando Tópico.

http://www.guj.com.br/posts/list/51615.java

Abraços!

ramilani12
bebad:
na pratica seria isso aqui assim oh:
PreparedStatement stmt = this.connection.prepareStatement
("select * from contatos WHERE nome like '%"+nome+"%' order by id");

ResultSet rs = stmt.executeQuery();

PreparedStatement não tem "suporte" ao LIKE teria que fazer assim:
E não tem sentido usar PreparedStatement com SQLInjection

PreparedStatement stmt = this.connection.prepareStatement
("select * from contatos WHERE nome like ? order by id");

stmt.setString(1 , nome + "%%");

ResultSet rs = stmt.executeQuery();
Criado 2 de fevereiro de 2007
Ultima resposta 2 de fev. de 2007
Respostas 5
Participantes 6