Like statement with parameters

2

I have the following procedure:

create procedure buscar(
in producto) 

begin 
select nombre from producto where nombre like'%'+producto+'%' 
end

but I get an error in the like

try using

create procedure buscar(
    in producto) 
    begin 
    select nombre from producto where nombre like'%'||producto||'%' 
    end

but when doing a search, I do not see similar products

for example I do

call Buscador_Producto('c');

and I do not see the products that start with c, I have to write the full name of the product

    
asked by Hugo Costilla 27.06.2018 в 12:43
source

1 answer

2

The problem you suffer is that the chain concatenation operator || works on engines like Oracle and PostgreSQL , but it does not work in MySQL nor is it standard in other database servers.

You can fix this by using the string concatenation operator CONCAT as follows:

CREATE PROCEDURE buscar(IN producto)
BEGIN
    SELECT
      nombre
    FROM producto
    WHERE
      nombre LIKE CONCAT('%', producto, '%')
END
    
answered by 27.06.2018 / 13:30
source