Function contrary to TRIM

4

How to insert characters into a varchar field in MySQL?

For example, in the update with trim vc you can remove certain characters from a field varchar ... but add?

Example: update tabela set campo = TRIM(leading '11' from campo);

    
asked by anonymous 12.02.2016 / 12:59

3 answers

7

MySQL has the function concat() to concatenate strings as it can receive N arguments you can put anything at the beginning and at the end.

update tabela set campo = concat('inicio ', campo, ' fim') where id = ?
    
12.02.2016 / 13:08
8

The opposite of doing a trimming is to do a padding , then the functions to be used should be PADL() and PADR() .

    
12.02.2016 / 13:34
-2

You can use the || (string concatenation):

select 'Hello' || ' ' || 'World'; returns Hello World .

    
23.03.2016 / 22:52