Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

stored procedure using like (MySQL)

How can I use the LIKE statement in stored procedures (MySQL) ?

I tried both but I still get errors:

..WHERE Des_Articolo LIKE '%nome_art%';

..WHERE Des_Articolo LIKE'%',nome_art,'%';

nome_art is declared as

CREATE PROCEDURE  ric_art (IN nome_art VARCHAR(100) , OUT msg VARCHAR(100))

Many thanks Roberto

like image 290
Roberto Avatar asked Jan 19 '23 16:01

Roberto


1 Answers

Use CONCAT to concatenate strings:

WHERE Des_Articolo LIKE CONCAT('%', nome_art, '%');

Note: This type of query is slow. If performance is an issue, you may want to consider an alternative approach such as full-text searching.

like image 141
Mark Byers Avatar answered Jan 28 '23 03:01

Mark Byers