SQL update all varchar column row

Aymen Ragoubi :

I have a table containing a single column containing varchar values. I want to update the column by splitting strings. For example, I have a table like this

'aaa/uuu', 'dfz/eza', 'sfd/aza'

I want to split all values by the character '/' in order to get this result

'aaa', 'dfz', 'sfd'

Could someone help me with this?

Ярослав Машко :

You should do this:

create table t(q varchar(255));

insert into t(q) values('abc/123');

update t
set q = SUBSTRING_INDEX(q, '/', 1);

select  SUBSTRING_INDEX(q, '/', 1)
from t;

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=395030&siteId=1