简体   繁体   中英

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. 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 . 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. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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