SQL _ Wildcards

SQL wildcards are used for searching one or more characters from data in a database.

SQL _ Wildcards

     

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)

Stu_Table

Stu_Id Stu_Name Stu_Class
1 Komal 10
2 Ajay 10
3 Rakesh 10
4 Bhanu 10
5 Santosh 10
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'

Result

Stu_Id Stu_Name Stu_Class
1 Komal 10
6 Kamal 10

Advertisements

Ads
Share on Google+Share on Google+

SQL _ Wildcards

Posted on: December 20, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

Ads
 

Discuss: SQL _ Wildcards  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0

Ads

 

Ads