How to concatenate a variable plus a message in the "Insert"?

Asked

Viewed 350 times

2

Concatenate a variable and a message in the insert? Example:

declare a int;
set a = 2;
insert into tb_usuario values ('a' + 'fez tal coisa');
  • 1

    In this case you are concatenated the character 'a' and not the variable a. Try CONCAT(a, 'did such a thing').

  • it worked. thank you

1 answer

0


Yes, have, you need to use a function for this, in case it is the CONCAT(). Then it would look something like this:

insert into tb_usuario values (concat('a', 'fez tal coisa'));

Although this case does not make much sense to do so, I hope you are using a field or variable there. Who knows want to do this:

insert into tb_usuario values (concat(a, 'fez tal coisa'));

I put in the Github for future reference.

This will insert 2fez alguma coisa.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.