从末尾开始,在特定索引处的字符串中插入子字符串.如何在mysql中? [英] Inserting substring in string at specific index counting from end. How to in mysql?
本文介绍了从末尾开始,在特定索引处的字符串中插入子字符串.如何在mysql中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在使用mysql insert()时遇到问题.
I have problem with mysql insert().
我在一个表中有可变长度的字符串(15-20个字符),我需要在每个字符串中添加4个字符.问题是,我需要在字符串末尾之前将它们恰好添加4个字符.
I have strings of variable length (15-20 chars) in a table, and I need to add 4 characters to every string. The catch is that I need to add them exactly 4 chars before the end of the string.
例如,给定输入字符串1234567890-123
,我需要在-"之前添加"ABCD",以使字符串变为1234567890ABCD-123
.
For example, given input string 1234567890-123
I need to add 'ABCD' before '-', so that the string becomes 1234567890ABCD-123
.
- 我尝试了insert()函数,但无法完成.
- 有解决方案吗?还是需要编写一个应用程序来做到这一点?
- 我使用MySQL 4.1.
推荐答案
替换提供了一种解决方案:
REPLACE provide a solution:
UPDATE `table` SET `column` = REPLACE(`column`, '-', 'ABCD-');
这篇关于从末尾开始,在特定索引处的字符串中插入子字符串.如何在mysql中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文