3
I’m doing a trial, I need to put a variable varchar in the query, but it doesn’t go with the simple quotes, I tried to concatenate like this or something but it’s no use:
set @comando := concat(@comando, '"'); //ao contrário tbm
set @comando := concat(@comando, classe);
set @comando := concat(@comando, '"');
I’ve had to put triple quotes too:
set @comando := concat(@comando, '''classe''');
What better way to concatenate or make Mysql recognize as a varchar?
Code:
delimiter $$
create procedure eixos_caminhao (in classe varchar(3))
begin
set @comando := 'select count(*) as qtdeCaminhoes';
set @comando:= concat(@comando, ' from tb_vbv where classe = ');
set @comando := concat(@comando, classe);
PREPARE myquery FROM @comando;
EXECUTE myquery;
end $$
delimiter;
You can do it like this:
concat(@comando, ' from tb_vbv where classe = \'');
– Roberto de Campos
The bar will work as an escape and will make the next character part of the
string
.– Roberto de Campos
then I have to surround with '' on both sides?
– Leandro Kojima
I’ll add an answer.
– Roberto de Campos
Beauty! I thank you
– Leandro Kojima