

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Find out if a varchar contains a percent sign in MySQL?
To find out a varchar contains a percent sign in MySQL, you can use LIKE operator. The syntax is as follows −
SELECT * FROM yourTableName WHERE yourColumnName like '%|%%' escape '|';
To understand the above syntax, let us create a table. The query to create a table is as follows −
mysql> create table FindPercentInVarcharDemo -> ( -> Id int NOT NULL AUTO_INCREMENT, -> Words varchar(30), -> PRIMARY KEY(Id) -> ); Query OK, 0 rows affected (0.51 sec)
Insert some records with % sign using insert command. The query is as follows −
mysql> insert into FindPercentInVarcharDemo(Words) values('This is a My%SQL Program'); Query OK, 1 row affected (0.19 sec) mysql> insert into FindPercentInVarcharDemo(Words) values('Java is an object oriented'); Query OK, 1 row affected (0.19 sec) mysql> insert into FindPercentInVarcharDemo(Words) values('C# is also an object%oriented'); Query OK, 1 row affected (0.57 sec)
Display all records from the table using select statement. The query is as follows −
mysql> select *from FindPercentInVarcharDemo;
The following is the output −
+----+-------------------------------+ | Id | Words | +----+-------------------------------+ | 1 | This is a My%SQL Program | | 2 | Java is an object oriented | | 4 | C# is also an object%oriented | +----+-------------------------------+ 3 rows in set (0.00 sec)
The following is the query to find out varchar contains % sign. The query is as follows −
mysql> select *from FindPercentInVarcharDemo where Words like '%|%%' escape '|';
The following is the output displaying only the values with a % sign −
+----+-------------------------------+ | Id | Words | +----+-------------------------------+ | 1 | This is a My%SQL Program | | 4 | C# is also an object%oriented | +----+-------------------------------+ 2 rows in set (0.00 sec)
- Related Questions & Answers
- How to find the absolute maximum of a matrix with sign if it contains negative values in R?
- Check if a string contains numbers in MySQL?
- Find maximum value from a VARCHAR column in MySQL
- Find the percentage of a student on basis of marks and add percent sign (%) to the result in SQL
- MySQL query to check if a string contains a word?
- How to find out if a Python object is a string?
- How to find a particular varchar id in MySQL from a list of values?
- C++ Program to find out if there is a pattern in a grid
- How to select a specific record from MySQL if date is in VARCHAR format?
- How to alter a MySQL Column from varchar(30) to varchar(100)?
- Check if a field contains a string in MongoDB?
- How to find If a given String contains only letters in Java?
- Find if an array contains a string with one mismatch in C++
- Return true or false in a MySQL select if another field contains a string?
- Find date record after a particular date from a column with VARCHAR type in MySQL
Advertisements