
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
How to extract the digit part from the string in MySQL?
Let us first create a table −
mysql> create table DemoTable -> ( -> StudentId varchar(100) -> ); Query OK, 0 rows affected (0.71 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('John19383'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values('Carol9999'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values('David123456'); Query OK, 1 row affected (0.15 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
Output
This will produce the following output −
+-------------+ | StudentId | +-------------+ | John19383 | | Carol9999 | | David123456 | +-------------+ 3 rows in set (0.00 sec)
Following is the query to extract the digit part from the string −
mysql> SELECT replace(reverse(FORMAT(reverse(StudentId), 0)), ',', '') as OnlyDigit from DemoTable;
Output
This will produce the following output −
+-----------+ | OnlyDigit | +-----------+ | 19383 | | 9999 | | 123456 | +-----------+ 3 rows in set (0.05 sec)
- Related Articles
- How to extract date from string in MySQL?
- How to extract part of a URL in MySQL?
- How can we extract a substring from a string in MySQL?
- Python – How to Extract all the digits from a String
- How to extract the first digit from a character column in an R data frame?
- How to extract only the numbers from a text field in MySQL?
- How to extract numbers from a string in Python?
- How to extract date from a string in Python?
- How to extract characters from a string in R?
- How to extract the first n characters from a string using Java?
- How to extract the last n characters from a string using Java?
- How to extract multiple integers from a String in Java?
- How to extract words from a string vector in R?
- How to extract number from string in R data frame?
- How to extract the area codes from a phone number with MySQL?

Advertisements