WHERE Clause (Cont.)
LIKE ConditionLIKE condition is used to specify a search for a pattern in a column.
| A ‘%’ sign can be used to define wildcards (missing letters in the pattern) both before and after the pattern. |
|
Using LIKE
|
|
SQL> select * from Persons where City = Sandnes;
*
ERROR at line 1:
ORA-00904: "SANDNES": invalid identifier
SQL> select * from Persons where FirstName like 'O%';
LASTNAME FIRSTNAME ADDRESS CITY
-------------- -------------- -------------- ------------
Hansen Ola Timoteivn 10 Sandnes
SQL> select * from Persons where FirstName like '%e';
LASTNAME FIRSTNAME ADDRESS CITY
-------------- -------------- -------------- ------------
Svendson Tove Borgvn 23 Sandnes
SQL> select * from Persons where FirstName like '%ar%';
LASTNAME FIRSTNAME ADDRESS CITY
-------------- -------------- -------------- ------------
Pettersen Kari Storgt 20 Stavanger
|
Customers table may be created by the following command:
SQL> create table Customers (
2 CustomerID varchar(16),
3 CompanyName varchar(32),
4 ContactName varchar(32),
5 Address varchar(64),
6 City varchar(32),
7 PostalCode varchar(16),
8 Country varchar(32) );
Note that the Customers table is for read only.