Wild Charcters :-
These characters are
used to provide pattern matching which means comparision to data is provided
with partial value.
ORACLE provides the
following wild characters.
i) _(Underscore) -> Represents single
character.
ii) %(Percentage) -> Represents group of
character.
Ø Inorder
to have wild characters for the comparision to partial data, LIKE operator is
used.
Ø If
these wild characters are formed in data, then the wild characters can be
converted to data using ‘\’ (backslash). It is represented through an option
called ‘ESCAPE’ , which is written after like operator.
Examples
:-
Display employee
number and employee name of all those employees whose names contain 4
characters.
Ans : select empno,
ename from emp
Where ename LIKE ‘----‘;
Display ename, job of
all those employees whose name starts with ‘A’.
Ans : select empno,
ename from emp
Where ename LIKE ‘A%’;
Display ename, job of
all those employees whose name ends with ‘S’.
Ans : select empno,
ename from emp
Where ename LIKE ‘%S’;
Display ename, job,
sal of all those employees whose name contain ‘A’.
Ans : Select ename,
job, sal from emp
Where ename LIKE ‘%A%’;
Display ename, sal of
all those employees whose salary is ending with ’00’.
Ans : Select ename,sal
from emp
Where sale LIKE ‘’;
Display ename, hiredate
of all those employees who have been hired in the year 81.
Ans : Select ename,
hiredate from emp
Where hiredate LIKE ‘%81’;
Display empno, ename,
hiredate of all those employees who have been hired in those months whose name
doesn’t starts with ‘A’.
Ans : Select empno,
ename, hiredate from emp
Where hiredate NOT LIKE ‘_ _ _ _A%’;
Display all those
employees whose designation contains ‘_’.
Ans : Select * from dept
Where dname like ‘%\_%’ ESCAPE ‘\’;
No comments:
Post a Comment