Concatenation can be useful for modifying column values "in place." : CONCAT « String « SQL / MySQL






Concatenation can be useful for modifying column values "in place."

       
mysql>
mysql> CREATE TABLE mytable
    -> (
    ->  name    VARCHAR(20)
    -> );
Query OK, 0 rows affected (0.01 sec)

mysql> INSERT INTO mytable (name)
    ->  VALUES
    ->          ('copper'),
    ->          ('gold'),
    ->          ('iron'),
    ->          ('lead'),
    ->          ('mercury'),
    ->          ('platinum'),
    ->          ('silver'),
    ->          ('tin')
    -> ;
Query OK, 8 rows affected (0.00 sec)
Records: 8  Duplicates: 0  Warnings: 0

mysql>
mysql> SELECT * FROM mytable;
+----------+
| name     |
+----------+
| copper   |
| gold     |
| iron     |
| lead     |
| mercury  |
| platinum |
| silver   |
| tin      |
+----------+
8 rows in set (0.00 sec)

mysql>
mysql>
mysql> UPDATE mytable SET name = CONCAT(name,'ide');
Query OK, 8 rows affected (0.00 sec)
Rows matched: 8  Changed: 8  Warnings: 0

mysql>
mysql> SELECT name FROM mytable;
+-------------+
| name        |
+-------------+
| copperide   |
| goldide     |
| ironide     |
| leadide     |
| mercuryide  |
| platinumide |
| silveride   |
| tinide      |
+-------------+
8 rows in set (0.00 sec)

mysql>
mysql> drop table mytable;
Query OK, 0 rows affected (0.00 sec)

   
    
    
    
    
    
    
  








Related examples in the same category

1.CONCAT(, [{, }...])
2.Use the CONCAT() and LEFT() functions to create registration codes for the employees.
3.Manipulate retrieved data from the Employees table.
4.Combining a Date and a Time into a Date-and-Time Value
5.Canonizing Not-Quite-ISO Date Strings
6.Add the setting NO_ZERO_IN_DATE to the SQL_MODE system variable.
7.To combine strings rather than pull them apart, use the CONCAT( ) function.
8.Concatenating Character Strings
9.Non-ISO results from the CONCAT( ) operation can be converted into ISO format three different ways as follows:
10.Generate Unique Sequential Numbers
11.Use Concat to create Initial for the name