I have column which stores values separated by a comma. It's something like this:
+--------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| breakfast_id | breakfast_english_menu |
+--------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| 1 | Canned Orange Juice- Can of 5 to 7 oz, Oatmeal- ½ T, Almonds - (12 almonds), Milk with Coffee or Milk with Chocolate (1T.) (Only one) |
+--------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
and so I would like to add a string after each comma at the beginning of a 'new value'. It would be something like
+--------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| breakfast_id | breakfast_english_menu |
+--------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| 1 | Canned Orange Juice- Can of 5 to 7 oz, [HI]Oatmeal- ½ T, [HI]Almonds - (12 almonds), [HI]Milk with Coffee or Milk with Chocolate (1T.) (Only one) |
+--------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
Any help or tip is welcomed.
As you have only a simple pattern use REPLACE
SELECT REPLACE('ned Orange Juice- Can of 5 to 7 oz, Oatmeal- ½ T, Almonds - (12 almonds), Milk with Coffee or Milk with Chocolate (1T.) (Only one)',', ',', [HI]')
| REPLACE('ned Orange Juice- Can of 5 to 7 oz, Oatmeal- ½ T, Almonds - (12 almonds), Milk with Coffee or Milk with Chocolate (1T.) (Only one)',', ',', [HI]') | |:----------------------------------------------------------------------------------------------------------------------------------------------------------- | | ned Orange Juice- Can of 5 to 7 oz, [HI]Oatmeal- ½ T, [HI]Almonds - (12 almonds), [HI]Milk with Coffee or Milk with Chocolate (1T.) (Only one) |
db<>fiddle here
For more complicated patterns, you would use regular expressions to find and replace.
If need be, you can nest REPLACE
comands one in another to repace more than one strintg
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.