Reputation: 53
In MySQL, I have a text column with "bla bla bla YYY=76767 bla bla bla".
I need to cut the number 76767.
How can I do it in SQL?
Upvotes: 5
Views: 20389
Reputation: 4141
If you wan't to UPDATE, use
UPDATE table_name SET column_name = REPLACE(column_name, '76767', '');
If you wan't to replace 76767
with bla bla bla
in your db, use
UPDATE table_name SET column_name = REPLACE(column_name, '76767', 'bla bla bla');
Upvotes: 0
Reputation: 382464
You can use
select substring_index(substring(mycol, instr(mycol, "=")+1), " ", 1)
to get the first token after the =
.
This returns 76767
.
This works in two steps :
substring(mycol, instr(mycol, "=")+1)
returns the string starting after the =
and
substring_index( xxx , " ", 1)
get the first element of the virtual array you'd got from a split by " ", and so returns the first token of xxx.
Upvotes: 8