Sie sind auf Seite 1von 11

========================

**Comparison Operators**
========================
--Equal(=)
--Not Equal(<>,!=)
--Greater than(>)
--greater than or equal to(>=)
--Lesser than(<)
--Lesser than or equal to(<=)
--Between .. and ..(inclusive)
--In(list of values)
--Like(match a character pattern)
--Is null
**EQUALS TO
SQL>select salary from employees where first_name='Neena';
SALARY
---------17000
**NOT EQUALS TO
SQL> select last_name from employees where salary!=4000;
LAST_NAME
------------------------OConnell
Grant
Whalen
Hartstein
Fay
Mavris
Baer
Higgins
Gietz
King
Kochhar
**LESS THAN
SQL> select last_name from employees where salary<6000;
LAST_NAME
------------------------OConnell
Grant
Whalen
Austin
Pataballa
Lorentz
Khoo
Baida
Tobias
Himuro
Colmenares
**GREATER THAN
SQL>select last_name from employees where salary>8000;
LAST_NAME

------------------------Hartstein
Baer
Higgins
Gietz
King
Kochhar
De Haan
Hunold
Greenberg
Faviet
Chen
**GREATER THAN OR EQUAL TO/LESS THAN OR EQUAL TO
SQL> select last_name from employees where salary=8000;
LAST_NAME
------------------------Weiss
Olsen
Smith
SQL> select last_name from employees where salary>=8000;
LAST_NAME
------------------------Hartstein
Baer
Higgins
Gietz
King
Kochhar
De Haan
Hunold
Greenberg
Faviet
Chen
LAST_NAME
------------------------Raphaely
Weiss
Fripp
Russell
Partners
Errazuriz
Cambrault
Zlotkey
Tucker
Bernstein
Hall
LAST_NAME
------------------------Olsen
King
Sully
McEwen
Smith
Vishney

Greene
Ozer
Bloom
Fox
Abel
LAST_NAME
------------------------Hutton
Taylor
Livingston
36 rows selected.
SQL> select last_name from employees where salary<=8000;
LAST_NAME
------------------------OConnell
Grant
Whalen
Fay
Mavris
Ernst
Austin
Pataballa
Lorentz
Sciarra
Urman
LAST_NAME
------------------------Popp
Khoo
Baida
Tobias
Himuro
Colmenares
Weiss
Kaufling
Vollman
Mourgos
Nayer
LAST_NAME
------------------------Mikkilineni
Landry
Markle
Bissot
KAPOOR
Marlow
Olson
Mallin
Rogers
Gee
Philtanker
**BETWEEN.. AND ..
SQL> select last_name from employees where salary between 5000 and 8000;

LAST_NAME
------------------------Fay
Mavris
Ernst
Sciarra
Urman
Popp
Weiss
Kaufling
Vollman
Mourgos
Olsen
LAST_NAME
------------------------Cambrault
Tuvault
Smith
Doran
Sewall
Marvins
Lee
Ande
Banda
Smith
Bates
LAST_NAME
------------------------Kumar
Grant
Johnson
25 rows selected.
**IN
SQL> select last_name from employees where salary in(5000,6000,8000);
LAST_NAME
------------------------Fay
Ernst
Weiss
Olsen
Smith
**LIKE
SQL> select first_name from employees where salary like 8000;
FIRST_NAME
-------------------Matthew
Christopher
Lindsey
SQL> select * from employees where last_name like '_lsen';
EMPLOYEE_ID FIRST_NAME

LAST_NAME

----------- -------------------- ------------------------EMAIL


PHONE_NUMBER
HIRE_DATE JOB_ID
SALARY
------------------------- -------------------- --------- ---------- ---------COMMISSION_PCT MANAGER_ID DEPARTMENT_ID
-------------- ---------- ------------153 Christopher
Olsen
COLSEN
011.44.1344.498718 30-MAR-98 SA_REP
8000
.2
145
80

**IS NULL
SQL> select first_name from employees where commission_pct is null;
SQL> select first_name from employees where commission_pct is not null;
=====================
**LOGICAL OPERATORS**
=====================
--AND
--OR

SQL> select first_name from employees where salary>10000 and job_id='SA_REP';


FIRST_NAME
-------------------Clara
Lisa
Ellen
SQL>select first_name, salary from employees where
job_id='SA_REP' or job_id='SA_MAN'
and
salary>10000;
FIRST_NAME
SALARY
-------------------- ---------John
14000
Karen
13500
Alberto
12000
Gerald
11000
Eleni
10500
Peter
10000
David
9500
Peter
9000
Christopher
8000
Nanette
7500
Oliver
7000
FIRST_NAME
SALARY
-------------------- ---------Janette
10000
Patrick
9500
Allan
9000
Lindsey
8000
Louise
7500

Sarath
Clara
Danielle
Mattea
David
Sundar

7000
10500
9500
7200
6800
6400

FIRST_NAME
SALARY
-------------------- ---------Amit
6200
Lisa
11500
Harrison
10000
Tayler
9600
William
7400
Elizabeth
7300
Sundita
6100
Ellen
11000
Alyssa
8800
Jonathon
8600
Jack
8400
FIRST_NAME
SALARY
-------------------- ---------Kimberely
7000
Charles
6200
35 rows selected.
SQL>select first_name, salary from employees
where
(job_id='SA_REP' or job_id='SA_MAN')
and
salary>10000;
FIRST_NAME
SALARY
-------------------- ---------John
14000
Karen
13500
Alberto
12000
Gerald
11000
Eleni
10500
Clara
10500
Lisa
11500
Ellen
11000
8 rows selected.
**ORDER BY CLAUSE
SQL> select first_name , hire_date from employees order by hire_date;
FIRST_NAME
-------------------Steven
Jennifer
Neena
Alexander
Bruce
Lex

HIRE_DATE
--------17-JUN-87
17-SEP-87
21-SEP-89
03-JAN-90
21-MAY-91
13-JAN-93

Susan
Hermann
Shelley
William
Daniel

07-JUN-94
07-JUN-94
07-JUN-94
07-JUN-94
16-AUG-94

FIRST_NAME
-------------------Nancy
Den
Payam
Alexander
Renske
Trenna
Nandita
Janette
Sarah
Michael

HIRE_DATE
--------17-AUG-94
07-DEC-94
01-MAY-95
18-MAY-95
14-JUL-95
17-OCT-95
27-JAN-96
30-JAN-96
04-FEB-96
17-FEB-96

SQL> select first_name , hire_date from employees order by hire_date desc;


FIRST_NAME
-------------------Amit
Sundita
Sundar
Steven
David
Hazel
Girard
Eleni

HIRE_DATE
--------21-APR-00
21-APR-00
24-MAR-00
08-MAR-00
23-FEB-00
06-FEB-00
03-FEB-00
29-JAN-00

**SUBSTITUTION VARIABLES
SQL> select employee_id, first_name from employees where department_id=&deptno;
Enter value for deptno: 10
old 1: select employee_id, first_name from employees where department_id=&dept
no
new 1: select employee_id, first_name from employees where department_id=10
EMPLOYEE_ID FIRST_NAME
----------- -------------------200 Jennifer
SQL> /
Enter value for deptno: 50
old 1: select employee_id, first_name from employees where department_id=&dept
no
new 1: select employee_id, first_name from employees where department_id=50
EMPLOYEE_ID
----------198
199
120
121
122
123
124

FIRST_NAME
-------------------Donald
Douglas
Matthew
Adam
Payam
Shanta
Kevin

125
126
127
128

Julia
Irene
James
Steven

EMPLOYEE_ID
----------129
130
131
132
133
134
135
136
137
138
139

FIRST_NAME
-------------------Laura
Mozhe
James
TJ
Jason
Michael
Ki
Hazel
Renske
Stephen
John

EMPLOYEE_ID
----------140
141
142
143
144
180
181
182
183
184
185

FIRST_NAME
-------------------Joshua
Trenna
Curtis
Randall
Peter
Winston
Jean
Martha
Girard
Nandita
Alexis

EMPLOYEE_ID
----------186
187
188
189
190
191
192
193
194
195
196

FIRST_NAME
-------------------Julia
Anthony
Kelly
Jennifer
Timothy
Randall
Sarah
Britney
Samuel
Vance
Alana

EMPLOYEE_ID FIRST_NAME
----------- -------------------197 Kevin
45 rows selected.
SQL>select salary, last_name from employees where job_id='&title'
Enter value for title: SA_REP
old 1: select salary, last_name from employees where job_id='&title'
new 1: select salary, last_name from employees where job_id='SA_REP'
SALARY LAST_NAME

---------10000
9500
9000
8000
7500
7000
10000
9500
9000
8000
7500

------------------------Tucker
Bernstein
Hall
Olsen
Cambrault
Tuvault
King
Sully
McEwen
Smith
Doran

SALARY
---------7000
10500
9500
7200
6800
6400
6200
11500
10000
9600
7400

LAST_NAME
------------------------Sewall
Vishney
Greene
Marvins
Lee
Ande
Banda
Ozer
Bloom
Fox
Smith

SALARY
---------7300
6100
11000
8800
8600
8400
7000
6200

LAST_NAME
------------------------Bates
Kumar
Abel
Hutton
Taylor
Livingston
Grant
Johnson

30 rows selected.
SQL> select last_name,&sal from employees where &condition;
Enter value for sal: 10000
Enter value for condition: salary>10000
old 1: select last_name,&sal from employees where &condition
new 1: select last_name,10000 from employees where salary>10000
LAST_NAME
10000
------------------------- ---------Hartstein
10000
Higgins
10000
King
10000
Kochhar
10000
De Haan
10000
Greenberg
10000
Raphaely
10000
Russell
10000
Partners
10000
Errazuriz
10000
Cambrault
10000

LAST_NAME
10000
------------------------- ---------Zlotkey
10000
Vishney
10000
Ozer
10000
Abel
10000
15 rows selected.
--using double ampersand
SQL>select last_name,&&sal from employees where &condition
SQL> /
Enter value for sal: 20000
Enter value for condition: salary>10000
old 1: select last_name,&&sal from employees where &condition
new 1: select last_name,20000 from employees where salary>10000
LAST_NAME
20000
------------------------- ---------Hartstein
20000
Higgins
20000
King
20000
Kochhar
20000
De Haan
20000
Greenberg
20000
Raphaely
20000
Russell
20000
Partners
20000
Errazuriz
20000
Cambrault
20000
LAST_NAME
20000
------------------------- ---------Zlotkey
20000
Vishney
20000
Ozer
20000
Abel
20000
15 rows selected.
SQL> /
Enter value for condition: salary>30000
old 1: select last_name,&&sal from employees where &condition
new 1: select last_name,20000 from employees where salary>30000
no rows selected
SQL> /
Enter value for condition: salary<3000
old 1: select last_name,&&sal from employees where &condition
new 1: select last_name,20000 from employees where salary<3000
LAST_NAME
20000
------------------------- ---------OConnell
20000
Grant
20000
Baida
20000
Tobias
20000

Himuro
Colmenares
Mikkilineni
Landry
Markle
Atkinson
Marlow

20000
20000
20000
20000
20000
20000
20000

LAST_NAME
20000
------------------------- ---------Olson
20000
Rogers
20000
Gee
20000
Philtanker
20000
Seo
20000
Patel
20000
Matos
20000
Vargas
20000
Sullivan
20000
Geoni
20000
Gates
20000
LAST_NAME
20000
------------------------- ---------Perkins
20000
Jones
20000
24 rows selected.
SQL>
SQL>
old
new

define employee_num=101
select salary from employees where employee_id=&employee_num;
1: select salary from employees where employee_id=&employee_num
1: select salary from employees where employee_id=101

SALARY
---------17000

Das könnte Ihnen auch gefallen