简体   繁体   English

如何从MySQL中包含字母数字字符串的列中仅提取字符串部分

[英]How to extract only String part from a column containing alphanumeric String in mysql

I have a alphaNumeric column in my mysql Database like this INV0001 and many values like INVI000040 where alphabets can be of variable length and integers can be of variable length. 我在MySQL数据库中有一个像这样的INV0001的alphaNumeric列,以及许多像INVI000040这样的值,其中字母可以是可变长度,而整数可以是可变长度。 I want to extract only the alphabetic string from this column . 我只想从此列中提取字母字符串。 I have searched on google I found about PATINDEX but that is not available in mysql . 我在google上搜索了有关PATINDEX的Google,但在mysql中找不到。 Please give some hint related to this problem . 请给出一些与此问题有关的提示。 I am not able to understand how to do this. 我不明白该怎么做。

MySQL does have any native regex replacement support, at least not of the time this answer was written. MySQL确实提供了任何本机正则表达式替换支持,至少在编写此答案时没有。 However, if you just want the letter components, you may try just removing all digits: 但是,如果只需要字母组成部分,则可以尝试删除所有数字:

SELECT
    col,
    REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(
        REPLACE(col, '9', ''), '8', ''), '7', ''), '6', ''), '5', ''), '4', ''),
         '3', ''), '2', ''), '1', ''), '0', '') AS alpha_only
FROM yourTable;

在此处输入图片说明

Demo 演示版

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM