This
will be used to search through the rows of database column based on the
pattern
you specify.
Syntax:
select * from <table_name> where <col>
like <pattern>;
Ex:
i) This will give the rows whose
marks are 100.
SQL> select * from student where marks like
100;
NO NAME MARKS
---
------- ---------
1
Sudha 100
ii) This will give the rows whose name start with ‘S’.
SQL> select * from
student where name like 'S%';
NO NAME MARKS
---
------- ---------
1
Sudha 100
2
Saketh 200
iii) This will give the rows whose name ends with ‘h’.
SQL> select * from
student where name like '%h';
NO NAME MARKS
---
------- ---------
2
Saketh 200
3
Ramesh
iV) This will give the rows whose name’s second letter start with ‘a’.
SQL> select * from
student where name like '_a%';
NO NAME MARKS
---
------- --------
2
Saketh 200
1
Jagan 300
2
Naren 400
3
Ramesh
4
Madhu
6
Rattu
V) This will give the rows whose name’s third letter start with ‘d’.
SQL> select * from
student where name like '__d%';
NO NAME MARKS
---
------- ---------
1
Sudha 100
4
Madhu
Vi) This will give the rows whose name’s second letter start with ‘t’
from ending.
SQL> select * from
student where name like '%_t%';
NO NAME MARKS
---
------- ---------
2
Saketh 200
6
Rattu
Vii) This will give the rows whose
name’s third letter start with ‘e’ from ending.
SQL> select * from student where name like
'%e__%';
NO NAME MARKS
---
------- ---------
2
Saketh 200
3
Ramesh
Viii) This will give the rows whose name
cotains 2 a’s.
SQL> select * from
student where name like '%a% a %';
NO NAME MARKS
--- ------- ----------
1
Jagan 300