Add characters to a string in sql

1

I have a very simple string like the following

  

'kyo, 1, koko, yuyu'

then I would like to add single quotes to each word to get something like

  

'' kyo ',' 1 ',' koko ',' yuyu ''

Even if possible I would like to respect the whole values, I guess I can separate them by commas with split but my real question is how can I add the quotes between the commas and return everything in a single string Any ideas? A thousand thanks.

    
asked by E.Rawrdríguez.Ophanim 13.09.2018 в 01:47
source

1 answer

3

You can use REPLACE()

'''' + REPLACE('kyo,1,koko,yuyu', ',', ''',''') + ''''

Basically we replace the , with another string, in this case by ',' . You have to keep in mind that to literally indicate a single quote you have to "escape" it with two quotes, that is% '' - > ' But with this we only contemplate the quotes between chains, we would miss the first and last quote that we added by concatenating them.

    
answered by 13.09.2018 / 02:37
source