變更MySQL欄位中某段文字的SQL語法

變更MySQL欄位中某段文字的SQL語法

My table looks like this

+—————-+

| column_name |

+—————-+

| abcOLDdefOLd |

| OLDjklmOLD |

| tuvwxyzOLDOLD|

+—————-+

To change only first occurrence of the string ‘OLD’ into ‘NEW’

we can use following query. (Replace wont work as it replaces all occurrences)

update table_name set column_name=insert(column_name,instr(column_name, ‘OLD’), length(‘OLD’), ‘NEW’);

Now select * from table_name will give output as

+—————-+

| column_name |

+—————-+

| abcNEWdefOLd |

| NEWjklmOLD |

| tuvwxyzNEWOLD|

+—————-+

Post Tags :

阿維

阿維雜記本的偷懶維護者