wildcard character can be used to substitute for any other character(s) in a string.
SQL Wildcard Characters
In SQL, wildcard characters are used with the SQL LIKE operator. SQL wildcards are used to search for data within a table. With SQL, the wildcards are:
|%||A substitute for zero or more characters|
|_||A substitute for a single character|
Like clause is used as condition in SQL query. Like clause compares data with an expression using wildcard operators. It is used to find similar data from the table.
There are two wildcard operators that are used in like clause.
- Percent sign
%: represents zero, one or more than one character.
- Underscore sign
_: represents only one character.
Example of LIKE clause
Consider the following Student table.
SELECT * from Student where s_name like 'A%';
The above query will return all records where s_name starts with character 'A'.
SELECT * from Student where s_name like '_d%';
The above query will return all records from Student table where s_name contain 'd' as second character.
SELECT * from Student where s_name like '%x';
The above query will return all records from Student table where s_name contain 'x' as last character.