Вы находитесь на странице: 1из 4

ORACLE CLAUSE

from clause is a mandatory clause in SELECT expression, It specifies the tables


from which data is to be retreived.

SYNTAX:

FROM table_name.....
expressions....

EG:- SELECT*
FROM customers
WHERE salary= 20000;

Operators in WHERE clause

=, <>(not equal), >, <, >=, <=,


BETWEEN(between an inclusive range),
LIKE(search for a pattern),
IN(to specify multiple possible values for a column)

combining AND & OR

SELECT * FROM Customers


WHERE Country='germany'
AND(City='Berlin' OR city='munchen');

The BETWEEN operator

The BETWEEN operator selects values within a range. The values can be numbers,
text, or dates.

SYNTAX:

SELECT column_name(s)
FROM table_name BETWEEN value1 AND value2;

Displays the values between the limit(upper limit and lower limit not included)

The NOT BETWEEN operator

SELECT * FROM products


WHERE Price NOT BETWEEN 10 AND 20;

Displays the values that are not in between the limit(upper limit and lower limit
included)

BETWEEN Operator with the Text Value Example

SELECT * FROM Products


WHERE ProductName BETWEEN 'C' AND 'M';

Displays the text(alphabets) between them(lower limit not included)*****

############

Q. Display employee name whose name starts between A-M


A. SQL> SELECT ENAME from emp
2 WHERE ENAME BETWEEN 'A' AND 'M';
ENAME
----------
ALLEN
JONES
BLAKE
CLARK
KING
ADAMS
JAMES
FORD

Q. Display employee between A-Z


A. SQL> SELECT ENAME
2 from emp;

ENAME
----------
SMITH
ALLEN
WARD
JONES
MARTIN
BLAKE
CLARK
SCOTT
KING
TURNER
ADAMS
JAMES
FORD
MILLER

Q. Display name between m-c


A. SQL> SELECT ENAME from emp
2 WHERE ENAME NOT BETWEEN 'D' AND 'M';

ENAME
----------
SMITH
ALLEN
WARD
MARTIN
BLAKE
CLARK
SCOTT
TURNER
ADAMS
MILLER

Q. Display between l to z
A. SQL> SELECT ENAME
from emp
WHERE ENAME NOT BETWEEN 'A' AND 'L';

ENAME
----------
SMITH
WARD
MARTIN
SCOTT
TURNER
MILLER

Q. Display the employee name and deptno whose working in 10 either 20


A. SQL> SELECT ENAME
2 from emp
3 WHERE DEPTNO IN(10,20);

ENAME
----------
SMITH
JONES
CLARK
SCOTT
KING
ADAMS
FORD
MILLER

Q. Display the employee name whose job is clerk and working in either 20 or 30 dept
A. SQL> SELECT ENAME DEPTNO
2 FROM emp
3 WHERE DEPTNO IN(20,30) AND JOB='CLERK';

DEPTNO
----------
SMITH
ADAMS
JAMES

Q. Display the employee name and salary whose job is salesman between 1000-3000
A. SQL> SELECT ENAME,SAL
2 from emp
3 WHERE SAL BETWEEN 1000 AND 3000
4 AND JOB='SALESMAN';

ENAME SAL
---------- ----------
ALLEN 1600
WARD 1250
MARTIN 1250
TURNER 1500

***********
1. When you want to see all employees whose name starts with S char. Then you can
use LIKE condition as follows
EG; select * from emp where ename like 's%'

2. you want to see all employees whose name ends with "d"
EG: SELect * FROM EMP WHERE ENAME like '%d';

3. you want to see all employees whose name starts with'A' and ends with 'd' like
'Abid'
EG: select * from emp where ename like 'A%d';

4. name contains character 'a' anywhere in the string


EG: select * from emp where ename like '%d%';
5. To see those employees whose name contains 'a' in second position
EG: select * from emp where ename like '_a%';

6. To see those employees whose name contains 'a' as last second character.
EG: select * from emp where ename like '%a_';

*********

Вам также может понравиться