Function contrary to TRIM

Asked

Viewed 210 times

4

How to insert characters in a field varchar in Mysql?

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

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

  • 1

    Add a character where? at the beginning at the end or at any position?

  • I want to add at the beginning, but if you can add in any position I will like to learn !

3 answers

9

The opposite of making a trimming (trimming) is making a padding (filling), so the functions to be used should be PADL() and PADR().

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 = ?

-2

You can use the || operator (string concatenation):

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

  • 1

    Doesn’t work for UPDATE, the field looks like 0 and both in the terminal and in PHP this select 'Hello' || ' ' || 'World'; returns 0 also. That is, you didn’t concatenate in mysql.

  • 1

    Hi, Jose. Note the tags under the question, the DB is mysql. In this case, the || does not serve. The || mysql is the OR for boolean values, and mysql | OR for numerical values.

Browser other questions tagged

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