Need help in the sql function

Hi, I have the column which return the string as below:

I need to have the above string converted to:

Just in case a value other than the first one might already have a dash in front of it, you can do this:

select replace(replace(string, ',-', ','), ',', ',-')

Well, you can use the below function in SQL to get what you are looking for.

SELECT '-' || REPLACE(your_column, ',', ',-') AS modified_column
FROM your_table;


original_string = "-AE,BH,BR,CA,CH,CN,GB,HK,IE,KW,MX,NL,OM,QA,SA,SG,US"

Split the original string into a list of country codes

country_codes = original_string.split(',')

Add a hyphen "-" before each country code and join them back into a string

modified_string = ','.join(['-' + code for code in country_codes])