ItSolutionStuff.com

MySQL Query to Remove Numbers from String in a Column Example

By Hardik Savani • February 5, 2023
MySql

Mysql custom fucntion is a very prety and intresting concept. In this posts i want to create one custom mysql function for remove numeric characters from table field value. this function through you can also remove numeric characters from string in mysql. in following sql query fire in your mysql or mssql database and check how it works. So, lets create function and how to use in select statement in sql query.

Create removeNumber function:

DROP FUNCTION IF EXISTS removeNumber;

DELIMITER |

CREATE FUNCTION removeNumber( str CHAR(32) ) RETURNS CHAR(16)

BEGIN

DECLARE i_val, len SMALLINT DEFAULT 1;

DECLARE ret CHAR(32) DEFAULT '';

DECLARE c CHAR(1);

SET len = CHAR_LENGTH( str );

REPEAT

BEGIN

SET c = MID( str, i_val, 1 );

IF c REGEXP '[[:alpha:]]' THEN

SET ret=CONCAT(ret,c);

END IF;

SET i_val = i_val + 1;

END;

UNTIL i_val > len END REPEAT;

RETURN ret;

END |

DELIMITER ;

Use With Select Query:

SELECT removeNumber(users.name) FROM `users`

I hope it can help you...

Tags: MySql
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

Node JS CRUD with MySQL Tutorial Example

Read Now →

How to Create a REST API using Node.js and MySQL?

Read Now →

How to Export Mysql Database using Command Line in Ubuntu?

Read Now →

How to Import Database in Mysql using Command Line in Ubuntu?

Read Now →

MySQL Query to Remove Special Characters from String

Read Now →

Laravel Where Clause with MySQL Function Example

Read Now →

How to Add MySQL Trigger from Migration in Laravel?

Read Now →

How to Import CSV File using MySQL?

Read Now →

How to fetch this week records in MySql ?

Read Now →

How to Check Empty or Null Data using MySQL Query?

Read Now →

How to Copy One Table Data into Another Table using MySQL?

Read Now →

How to count unique domains from email address field in MySQL ?

Read Now →

Which MySQL Datatype use for Store an IP Address?

Read Now →

Mysql Hexadecimal Color Code Store in Binary Datatype Example

Read Now →