- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- 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 count number of specific symbols in a row in MySQL?
You can use LENGTH() to count number of specific symbols in a row. Let us first create a table −
mysql> create table DemoTable ( Value varchar(200) ); Query OK, 0 rows affected (0.54 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('?1234?6789?5656?324?'); Query OK, 1 row affected (0.17 sec)
Following is the query to display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+----------------------+ | Value | +----------------------+ | ?1234?6789?5656?324? | +----------------------+ 1 row in set (0.00 sec)
Following is the query to count number of specific symbols in a row in MySQL −
mysql> SELECT LENGTH(Value) - LENGTH(REPLACE(Value,'?','')) from DemoTable;
This will produce the following output −
+-----------------------------------------------+ | LENGTH(Value) - LENGTH(REPLACE(Value,'?','')) | +-----------------------------------------------+ | 5 | +-----------------------------------------------+ 1 row in set (0.03 sec)
Advertisements