MainMenu

Home Core Java Overview Maven Tutorials

Sunday, 15 January 2017

SQL Wildcards with Example

To fetch the result without using complete string. Better will be understood with below examples :

Example : Consider the following table Table: Salary
<
Emp_idEmp_nameEmp_regEmp_salary
01chandanE_0125000
02adhirajE_0230000
03raghuE_0335000
04raghunathE_0436000
05AlaxE_0440000
% wildcard:

Select * from Salary where Emp_name like "%ndan"

Result: Records starting from any character but followed by 'ndan' will appear Table: Salary
Emp_idEmp_nameEmp_regEmp_salary
01chandanE_0125000
wildcard %:

Select * from Salary where Emp_name like "ra%"

Result: All the records staring from 'ra' character will appear Table: Salary
Emp_idEmp_nameEmp_regEmp_salary
03raghuE_0335000
04raghunathE_0436000
_wildcard:

Select * from Salary where Emp_name like "-raj"

Result: Table: Salary
<
Emp_idEmp_nameEmp_regEmp_salary
02adhirajE_0230000
05AlaxE_0440000
[a-c]%wildcard:

Select * from Salary where Emp_name like "[a-c]%"

Result: Records starting from from any 'a, b, c' charcater will appear. Table: Salary
<
Emp_idEmp_nameEmp_regEmp_salary
01chandanE_0125000
02adhirajE_0230000
05AlaxE_0440000
[!]%wildcard :

Select * from Salary where Emp_name = "[!ar]%"

Result: All the records starting from letter a, r will NOTappear Table: Salary
Emp_idEmp_nameEmp_regEmp_salary
01chandanE_0125000

Tag : What is Wildcard in SQL ?

No comments:

Post a Comment