articles

SQL Wildcards

Anonymous User7974 04-Jul-2011

SQL wildcards are used for searching one or more characters from table 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 must be used with LIKE operator. 

  There are many wildcards are used in SQL database, Here in which some important wildcards are given below:

1.   ‘%’ wildcards:

     ‘%’ allows you to match any string of any length that means a substitute for zero or more characters.

Example:    

Now we want to select the User whose name that starts with "ar" from the "userlogininfo" table.

 SelectQuery:   

 select username from userlogininfo where UserName like 'ar%' 
Output:

ArunKumar

Arunsingh

2.  ‘_’ wildcards:

‘_ ‘allows you to match on a single character that means ‘_’is looking for only one character.

 Example: 

 Now we want to select the user with a first name that starts with any character, followed by "runsingh" from the "userlogininfo" table.

 Select Query

 select username from userlogininfo where UserName like _runsingh'
Output:

         Arunsingh

3. [charlist] wildcards:

[charlist] wildcards are used for any single character in charlist.

 Example:

Now we want to select the user with a name that starts with "a" or "v" from the "userlogininfo" table.

Select Query:
  select username from userlogininfo where UserName like '[av]%'
Output:

  ArunKumar

 Arunsingh

Varunsingh

 


Updated 22-Mar-2018
I am a content writter !

Leave Comment

Comments

Liked By