[英]How to replace numeric character with “%” in MySQL?
How to replace numeric character with "%" in MySQL ? 如何在MySQL中用“%”替换数字字符?
ie : abcd 1234 zz => abcd %%%% zz 即:abcd 1234 zz => abcd %%%% zz
What I have : 我有的 :
Declare cursorVideoTitles cursor for select temp_playList.VideoTitle
from temp_playList where temp_playList.VideoTitle regexp '^[A-Za-z0-9]+$';
cursorVideoTitles contain all alphanumeric video titles. cursorVideoTitles包含所有字母数字视频节目。 now after this I need to replace numeric character with "%"
在此之后,我需要用“%”替换数字字符
Reason for this : I need to search it in other table which have same alphabets. 原因:我需要在其他具有相同字母表的表中进行搜索。 so 1st I take all those values in cursor variable and iterate it with like query,so i will get matching records.
所以我先把所有这些值都放在游标变量中,并用类似的查询迭代它,这样我就会得到匹配的记录。
Unfortunately, MySQL doesn't have a regular expression replace function, you have to replace each digit separately. 不幸的是,MySQL没有正则表达式替换功能,你必须分别替换每个数字。
SELECT
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(VideoTitle, '0', '%'),
'1', '%'),
'2', '%'),
'3', '%'),
'4', '%'),
'5', '%'),
'6', '%'),
'7', '%'),
'8', '%'),
'9', '%') AS TitleMasked
The easiest thing I can think is something like: 我能想到的最简单的事情是:
SELECT REPLACE('abcd1234zz', '1234', '%%%%'); SELECT REPLACE('abcd1234zz','1234','%%%%');
This query looks if there are 1234 in a value and replace them with four % 此查询查看值中是否有1234并将其替换为4%
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.