Concatenate text to an existing SQL column

1

I have the following SQL :

UPDATE tabela SET peso = peso "KG"

I need to add the KG tag to the weight field, but if I do it the way I did it does not work. How could I do it?

    
asked by anonymous 28.02.2018 / 16:11

2 answers

4

Use single quotation marks to concatenate the text 'KG'

SQL SERVER:

In addition to the CONCAT () function you can use the + to concatenate the current value of the column with KG :

UPDATE tabela SET peso = peso + 'KG'

SQLite:

Use || to concatenate , CONCAT here does not work.

UPDATE Tabela Set Coluna = Coluna || 'KG'

MySQL:

Use CONCAT () :

UPDATE tabela SET peso = CONCAT(peso, 'KG');

Note: It is also possible to do with || as in SQLite but for this you must configure MySQL to accept, setting sql_mode to PIPES_AS_CONCAT .

PostgreSQL:

In addition to the CONCAT () function, you can use || to concatenate .

UPDATE Tabela Set Coluna = Coluna || 'KG'

Oracle:

In addition to the CONCAT () function, you can use || to concatenate.

UPDATE Tabela Set Coluna = Coluna || 'KG'

All of the above commands have been tested in SQLFiddle .

    
28.02.2018 / 16:15
3

You have to concatenate what is stored plus tag KG:

UPDATE tabela SET peso = CONCAT(peso, " KG");
    
28.02.2018 / 16:15