SQL wildcards are used for searching one or more characters from data in a database. The SQL wildcards substitute one or more character, whenever there is a search for data in a table of the database. The Wildcards is used with LIKE operator.
Understand with Example
The Tutorial illustrate an example from SQL_Wildcards. To understand Wildcards in SQL, we create a table name'Stu_Table' using create statement. The insert into add records or rows into the table. When you want to see the records from a table, the select statement is used, which returns you the records inserted into the table 'Stu_Table'. SQL wildcards helps you to search the data from table based on substituting one or more character .The LIKE operator is always used with wildcards.
Create Table Stu_Table
create table Stu_Table(Stu_Id integer(2), Stu_Name varchar(15), Stu_Class varchar(10))
Insert data into Stu_Table
insert into Stu_Table values(1,'Komal',10) insert into Stu_Table values(2,'Ajay',10) insert into Stu_Table values(3,'Rakesh',10) insert into Stu_Table values(4,'Bhanu',10) insert into Stu_Table values(5,'Santosh',10) insert into Stu_Table values(6,'Kamal',10)
SQL % Wildcards Syntax
SELECT ColumnName(s) FROM TableName WHERE ColumnName LIKE pattern
SQL % Wildcards Query
Now we want to select the persons name those name starts with "k" , second character followed by any character and last three character are "mal"
from the table above.
select * from stu_table where stu_name like 'k_mal'