Hi, I have the column which return the string as below:
-AE,BH,BR,CA,CH,CN,GB,HK,IE,KW,MX,NL,OM,QA,SA,SG,US
I need to have the above string converted to:
-AE,-BH,-BR,-CA,-CH,-CN,-GB,-HK,-IE,-KW,-MX,-NL,-OM,-QA,-SA,-SG,-US
Hi, I have the column which return the string as below:
-AE,BH,BR,CA,CH,CN,GB,HK,IE,KW,MX,NL,OM,QA,SA,SG,US
I need to have the above string converted to:
-AE,-BH,-BR,-CA,-CH,-CN,-GB,-HK,-IE,-KW,-MX,-NL,-OM,-QA,-SA,-SG,-US
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;
Thanks
original_string = "-AE,BH,BR,CA,CH,CN,GB,HK,IE,KW,MX,NL,OM,QA,SA,SG,US"
country_codes = original_string.split(',')
modified_string = ','.join(['-' + code for code in country_codes])
print(modified_string)