- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to get last 12 digits from a string in MySQL?
You can use RIGHT() function from MySQL to get the last 12 digits from a string. Let us first create a table −
mysql> create table DemoTable ( Number varchar(200) ); Query OK, 0 rows affected (0.59 sec)
Insert records in the table using insert command −
mysql> insert into DemoTable values('7437647847847474374747464647484949959958484'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values('9990000399494959697080800007007070808080808'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('1211111212344554444443333345555554433333333333333'); Query OK, 1 row affected (0.14 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable;
This will produce the following output −
+---------------------------------------------------+ | Number | +---------------------------------------------------+ | 7437647847847474374747464647484949959958484 | | 9990000399494959697080800007007070808080808 | | 1211111212344554444443333345555554433333333333333 | +---------------------------------------------------+ 3 rows in set (0.00 sec)
Following is the query to get last 12 digits from a string in MySQL −
mysql> select right(Number,12) as `Last 12 Digit From String` from DemoTable;
This will produce the following output −
+---------------------------+ | Last 12 Digit From String | +---------------------------+ | 949959958484 | | 070808080808 | | 333333333333 | +---------------------------+ 3 rows in set (0.00 sec)
- Related Articles
- Get digits from a record in MySQL?
- How to get last 4 characters from string in C#?
- MySQL query to get a substring from a string except the last three characters?
- Get all digits from a string in Java
- Get the sum of last 3 digits from all the values in a column with MySQL
- How to get the second last record from a table in MySQL?
- How to get last 2 characters from string in C# using Regex?
- Get the index of last substring in a given string in MySQL?
- How do you select from MySQL where last value in a string = x?
- Get the last record from a table in MySQL database with Java?
- Get Last Entry in a MySQL table?
- Get all rows apart from first and last in MySQL
- How to remove the last character from a string in Java?
- Python – How to Extract all the digits from a String
- How to ORDER BY last 2 character string in MySQL?

Advertisements