Reputation: 55
I have 3 columns in my table:
+-+-+-+-+-+-+-+-+-+-+-++
+ ID + Name + Cell +
++++++++++++++++++++++++
+ 1 + FB + /moon/ta +
+ 2 + GO + /ta/ta +
+ 3 + MO + /ta/mon +
+ 4 + SS + /ta +
+ 4 + SS + /ta/o/ta +
+-+-+-+-+-+-+-+-+-+-+-++
I want to replace all "/ta" with "/rr" in cell that start of string, like:
+-+-+-+-+-+-+-+-+-+-+-++
+ ID + Name + Cell +
++++++++++++++++++++++++
+ 1 + FB + /moon/ta +
+ 2 + GO + /rr/ta +
+ 3 + MO + /rr/mon +
+ 4 + SS + /rr +
+ 4 + SS + /rr/o/ta +
+-+-+-+-+-+-+-+-+-+-+-++
How can I do this in SQL?
Upvotes: 2
Views: 1458
Reputation: 1270021
I think this does what you want:
update table t
set cell = concat('/rr', substr(cell, 4))
where cell like '/ta%';
Upvotes: 3