Home > Database > Mysql Tutorial > How can we get the last number of characters from the data stored in a MySQL table column?

How can we get the last number of characters from the data stored in a MySQL table column?

PHPz
Release: 2023-08-25 23:57:08
forward
1048 people have browsed it

我们如何从 MySQL 表列中存储的数据中获取最后的字符数?

To get the last number of characters from the data stored in a MySQL table column, we can use the MySQL RIGHT() function. It will return the number of characters specified as argument. We need to provide the name of the column and the specific record from which we want to get the last character as its first parameter. To demonstrate this, let's take an example of a table named "examination_btech" which contains the exam details of the following students -

mysql> Select * from examination_btech;
+-----------+----------+--------+
| RollNo    | Name     | Course |
+-----------+----------+--------+
| 201712001 | Rahul    | B.tech |
| 201712002 | Raman    | B.tech |
| 201712003 | Sahil    | B.tech |
| 201712004 | Shalini  | B.tech |
| 201712005 | Pankaj   | B.tech |
| 201712006 | Mohan    | B.tech |
| 201712007 | Yash     | B.tech |
| 201712008 | digvijay | B.tech |
| 201712009 | Gurdas   | B.tech |
| 201712010 | Preeti   | B.tech |
+-----------+----------+--------+
10 rows in set (0.00 sec)
Copy after login

Now if we want to get the last three characters from a series of rolls then This can be done with the help of the RIGHT() function as shown below-

mysql> Select RIGHT(RollNo, 3) FROM examination_btech;
+------------------+
| RIGHT(RollNo, 3) |
+------------------+
| 001              |
| 002              |
| 003              |
| 004              |
| 005              |
| 006              |
| 007              |
| 008              |
| 009              |
| 010              |
+------------------+
10 rows in set (0.00 sec)
Copy after login

The above is the detailed content of How can we get the last number of characters from the data stored in a MySQL table column?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template