Menu

Friday, 3 January 2014

LIKE operator [wildcard characters]


 
Wildcard
Description
  -
   (Underscore)
Matches any single character
%
Matches a string of one or more characters
[ ]
Matches any single character within the
specified range (e.g. [a-f]) or set (e.g.
[abcdef]).
[^]
Matches any single character not within the
specified range (e.g. [^a-f]) or set (e.g.
[^abcdef]).

                                                 Figure:suryagroops_0005 (tbl_emp)

Examples

                                               
Emp_id
Emp_name
1
Suryagroops
2
Suresh
3
Mayank dixit
4
Suryagroops
5
Ramesh
6
Ramesh
7
Shalini
8
Sushil
       
Find all Emp_Name ends with ‘sh’

SELECT        emp_name
FROM            tbl_emp
WHERE        (emp_name LIKE '%sh')

Result-

Emp_Name
Suresh
Ramesh
Ramesh

Find all Emp_Name includes ‘sh’ anywhere in the name

SELECT        emp_name
FROM            tbl_emp
WHERE        (emp_name LIKE '% sh %')

Result-

Emp_Name
Suresh
Ramesh
Ramesh
Shalini
Sushil

No comments: