stored procedure does not return response [mysql]

1

Hello all good morning, I have to do a search in a form of c #, for this I have a procedure stored in MYSQL that will show the results of a certain word entered in a textbox, the issue is that the sp does not return any result, the procedure code is as follows:

CREATE DEFINER='administrador'@'%' PROCEDURE 'spBuscarFunNombre'(
in textoBuscar varchar(100)
)
BEGIN
SELECT * FROM funcionario WHERE nombres LIKE '% textoBuscar %' ;
END

I try it in the mysql console and it does not bring records (tested with records that exist in the table).

Will I be doing something wrong? I do not mark error the sp.

Greetings to all and thanks

    
asked by Nicolas Ezequiel Almonacid 14.08.2018 в 17:27
source

2 answers

0

Here are some examples of the LIKE wildcard:

SELECT * FROM clientes WHERE nombre LIKE '%m%';

In the upper code we are looking for clients that contain an 'm' in the name.

SELECT * FROM clientes WHERE nombre LIKE 'M%';

In the upper code we are looking for clients whose name starts with 'M'.

SELECT * FROM clientes WHERE nombre LIKE '%a';

In the upper code we are looking for clients whose name ends with 'a'.

SELECT * FROM clientes WHERE nombre LIKE '_a%';

In the superior code we are looking for the clients whose name has the second character the 'a'.

SELECT * FROM clientes WHERE nombre LIKE '_______';

In the upper code we are looking for clients whose name is 7 characters long.

SELECT * FROM clientes WHERE nombre LIKE '%a%' or nombre LIKE '%r%' ;

In the upper code we are looking for customers whose name has an 'a' and an 'r'.

Referral Link

In your case, the word'Search text 'is a parameter so your syntax should look like this:

CREATE DEFINER='administrador'@'localhost' PROCEDURE 'spBuscarFunNombre'(in textoBuscar varchar(100))
BEGIN 
   SELECT * FROM funcionario WHERE nombres LIKE '%' + textoBuscar + '%'; 
END;
    
answered by 14.08.2018 / 17:52
source
0

The syntax is as follows:

 CREATE DEFINER = 'administrador'@'%'
 PROCEDURE test.spBuscarFunNombre(in textoBuscar varchar(100) )
 BEGIN 
 SELECT * FROM funcionario WHERE nombres LIKE CONCAT('%', textoBuscar, '%');
 END

Result:

I hope it's your help, regards ...

    
answered by 14.08.2018 в 18:18