Академический Документы
Профессиональный Документы
Культура Документы
1.
:
select,
.
C :
:
26
1. JOBS Hr,
.
, :
JOB_TITLE
President
Administration Vice President
Administration Assistant
MIN_SALARY
20000
15000
3000
:
JOBS,
:
Select j ob_ti tl e, min_s alary
from hr. jobs;
Danald OConnell
Douglas Grant
Jennifer Whalen
2600,00
2600,00
4400,00
31200
31200
52800
:
, ,
:
Select f ist_n am e||last_ name as ,
salary a s , salary *12 a s
From hr. emplo ye es;
(||)
, ,
12.
3. locations hr,
, state_province.
:
2
locations ,
state_province .
4. , id , i d
, ,
job_histor y. 1993,
1998, ,
id AC_ACCOUNT AC_MGR.
id .
, :
DEPARTMENT_ID START_DATE END_DATE
110
28.10.93
15.03.97
90
01.07.94
31.12.98
JOB_ID
AC_MGR
AC_ACCOUNT
:
Select d epart me nt_id, s tart_ da te, end_ date, j ob_id
from hr. job_h is tory
where st art_d at e > 01. 01.19 93
and end_ date < 01.01.1 999
and job_ id= AC _ACCOUNT or jo b_id= A C_MGR
Order by depa rt ment_id desc;
5. , i d ,
, ( job_id)
hr.job_hist or y. :
Job_id IT_PROG,
" ";
Job_id AC_MGR,
" ";
,
" ".
, :
Id
102
101
100
13.01.93
24.07.98
21.09.89
27.10.93
28.10.93
15.03.97
1 .
1 ( 1)
1.
=((30*20)/10)+(20*10)
2.
location hr,
postal_code
3.
,
3 .
.
, hr.employees
,
. ,
.
Ellen
Abel
ELLAB
Sundar
Ande
SUNAN
Mozhe
Atkinson
MOZAT
David
Austin
DAVAU
Hermann
Baer
HERBA
Shelli
Baida
SHEBA
Amit
Banda
AMIBA
Elizabeth
Bates
ELIBA
4
Sarah
Bell
SARBE
4.
, ,
employees hr. salary,
job_id.
, .
AC_MGR
12000
12000
12000.00
AC_ACCOUNT
8300
8300
8300.00
IT_PROG
9000
4200
5760.00
ST_MAN
8200
5800
7280.00
AD_ASST
4400
4400
4400.00
PU_MAN
11000
11000
11000.00
SH_CLERK
4200
2500
3215.00
AD_VP
17000
17000
17000.00
FI_ACCOUNT
9000
6900
7920.00
MK_MAN
13000
13000
13000.00
2 ( 1)
1.
employees hr,
Donald OConnell
2600,00
2262
Douglas Grant
2600,00
2262
Jennifer Whalen
4400,00
3828
Michael Hartstein
13000,00
11310
Pat Fay
6000,00
5220
Susan Mavris
6500,00
5655
Hermann Baer
10000,00
8700
Shelley Higgins
12000,00
10440
William Gietz
8300,00
7221
Steven King
24000,00
20880
Neena Kochhar
17000,00
14790
13 .
2.
, , ,
( JOB_ID) ( HIRE_DATE)
hr.employees.
, 1995 1999
, , AD_PRES, AD_VP
AD_ASST. .
BETWEEN IN.
, .
Donald
OConnell
SH_CLERK
21.06.1999
Jennifer
Whalen
AD_ASST
17.09.1987
Michael
Hartstein
MK_MAN
17.02.1996
Pat
Fay
MK_REP
17.08.1997
Steven
King
AD_PRES
17.06.1987
3.
,
hr.employees,
,
( ).
,
Donald
OConnell
2600,00
21.06.1999
122
Douglas
Grant
2600,00
13.01.2000
115
Jennifer
Whalen
4400,00
17.09.1987
263
Michael
Hartstein
13000,00
17.02.1996
162
Pat
Fay
6000,00
17.08.1997
144
Susan
Mavris
6500,00
07.06.1994
182
Hermann
Baer
10000,00
07.06.1994
182
Shelley
Higgins
12000,00
07.06.1994
182
William
Gietz
8300,00
07.06.1994
182
4.
, ,
employees hr. salary,
job_id.
, .
AC_MGR
12000
12000
12000.00
8300
8300
8300.00
IT_PROG
9000
4200
5760.00
ST_MAN
8200
5800
7280.00
AD_ASST
4400
4400
4400.00
PU_MAN
11000
11000
11000.00
SH_CLERK
4200
2500
3215.00
AD_VP
17000
17000
17000.00
9000
6900
7920.00
13000
13000
13000.00
AC_ACCO
UNT
FI_ACCOU
NT
MK_MAN
3 ( 1)
1.
2.
location hr,
postal_code
3.
, ,
( JOB_ID) hr.employees.
:
JOB_ID SA_REP,
" ";
JOB_ID SA_MAN,
" ";
"".
,
Joshua
Patel
Jose Manuel
Urman
Jonathon
Taylor
John
Chen
John
Seo
John
Russell
Jennifer
Whalen
Jennifer
Dilly
Jean
Fleaur
4.
, ,
employees hr. salary,
job_id.
, .
AC_MGR
12000
12000
12000.00
8300
8300
8300.00
IT_PROG
9000
4200
5760.00
ST_MAN
8200
5800
7280.00
AD_ASST
4400
4400
4400.00
PU_MAN
11000
11000
11000.00
SH_CLERK
4200
2500
3215.00
AD_VP
17000
17000
17000.00
9000
6900
7920.00
13000
13000
13000.00
AC_ACCO
UNT
FI_ACCOU
NT
MK_MAN
10
4 ( 1)
1.
employees hr,
Donald OConnell
2600,00
2262
Douglas Grant
2600,00
2262
Jennifer Whalen
4400,00
3828
Michael Hartstein
13000,00
11310
Pat Fay
6000,00
5220
Susan Mavris
6500,00
5655
Hermann Baer
10000,00
8700
Shelley Higgins
12000,00
10440
William Gietz
8300,00
7221
Steven King
24000,00
20880
Neena Kochhar
17000,00
14790
13 .
2.
, , ,
( JOB_ID) ( HIRE_DATE)
hr.employees.
, 1995 1999
, , AD_PRES, AD_VP
AD_ASST. .
BETWEEN IN.
, .
11
Donald
OConnell
SH_CLERK
21.06.1999
Jennifer
Whalen
AD_ASST
17.09.1987
Michael
Hartstein
MK_MAN
17.02.1996
Pat
Fay
MK_REP
17.08.1997
Steven
King
AD_PRES
17.06.1987
3.
,
3 .
.
, hr.employees
,
. ,
.
Ellen
Abel
ELLAB
Sundar
Ande
SUNAN
Mozhe
Atkinson
MOZAT
David
Austin
DAVAU
Hermann
Baer
HERBA
Shelli
Baida
SHEBA
Amit
Banda
AMIBA
Elizabeth
Bates
ELIBA
Sarah
Bell
SARBE
12
4.
, ,
employees hr. salary,
job_id.
, .
AC_MGR
12000
12000
12000.00
AC_ACCOUNT
8300
8300
8300.00
IT_PROG
9000
4200
5760.00
ST_MAN
8200
5800
7280.00
AD_ASST
4400
4400
4400.00
PU_MAN
11000
11000
11000.00
SH_CLERK
4200
2500
3215.00
AD_VP
17000
17000
17000.00
FI_ACCOUNT
9000
6900
7920.00
MK_MAN
13000
13000
13000.00
13
5 ( 1)
1.
=((30*40)/10)+(20*10)
2.
employees hr,
,
50.
3.
, ,
( JOB_ID) hr.employees.
:
JOB_ID
JOB_ID
"".
,
Joshua
Patel
Jose Manuel
Urman
Jonathon
Taylor
John
Chen
John
Seo
John
Russell
Jennifer
Whalen
Jennifer
Dilly
Jean
Fleaur
4.
, ,
employees hr.
salary, job_id.
, .
AC_MGR
12000
12000
12000.00
AC_ACCOUNT
8300
8300
8300.00
IT_PROG
9000
4200
5760.00
ST_MAN
8200
5800
7280.00
AD_ASST
4400
4400
4400.00
PU_MAN
11000
11000
11000.00
SH_CLERK
4200
2500
3215.00
AD_VP
17000
17000
17000.00
FI_ACCOUNT
9000
6900
7920.00
MK_MAN
13000
13000
13000.00
15
6 ( 1)
1.
employees hr,
Donald OConnell
2600,00
2262
Douglas Grant
2600,00
2262
Jennifer Whalen
4400,00
3828
Michael Hartstein
13000,00
11310
Pat Fay
6000,00
5220
Susan Mavris
6500,00
5655
Hermann Baer
10000,00
8700
Shelley Higgins
12000,00
10440
William Gietz
8300,00
7221
Steven King
24000,00
20880
Neena Kochhar
17000,00
14790
13 .
2.
, , ,
hr.employees.
,
10000 .
. ,
.
16
John
Russell
14000,00
0,40
Janette
King
10000,00
0,35
Gerald
Cambrault
11000,00
0,30
Ellen
Abel
11000,00
0,30
Alberto
Errazuriz
12000,00
0,30
Karen
Partners
13500,00
0,30
Peter
Tucker
10000,00
0,30
Clara
Vishney
10500,00
0,25
Lisa
Ozer
11500,00
0,25
Harrison
Bloom
10000,00
0,20
Eleni
Zlotkey
10500,00
0,20
3.
,
hr.employees. (
COMMISSION_PCT . ,
, 0.
, .
Alexander
Hunold
Alexander
Khoo
Alexis
Bull
Allan
McEwen
0,35
Alyssa
Hutton
0,25
Amit
Banda
0,1
Anthony
Cabrio
0
17
Britney
Everett
Bruce
Ernst
4.
, ,
employees hr
( salary).
,
24000
2100
6461.68
18
7 ( 1)
1.
=((30*70)/10)+(20*10)
2.
employees hr,
,
50.
3.
, ,
( JOB_ID) hr.employees.
:
JOB_ID SA_REP,
" ";
JOB_ID SA_MAN,
" ";
"".
,
Joshua
Patel
Jose Manuel
Urman
Jonathon
Taylor
John
Chen
John
Seo
John
Russell
19
Jennifer
Whalen
Jennifer
Dilly
Jean
Fleaur
4.
, ,
employees hr
( salary).
,
24000
2100
6461.68
20
8 ( 1)
1.
2.
employees hr,
,
50.
3.
,
hr.employees. (
COMMISSION_PCT . ,
, 0.
, .
Alexander
Hunold
Alexander
Khoo
Alexis
Bull
Allan
McEwen
0,35
Alyssa
Hutton
0,25
Amit
Banda
0,1
Anthony
Cabrio
Britney
Everett
Bruce
Ernst
4.
, ,
employees hr
( salary).
,
21
24000
2100
6461.68
22
9 ( 1)
1.
employees hr,
Donald OConnell
2600,00
2262
Douglas Grant
2600,00
2262
Jennifer Whalen
4400,00
3828
Michael Hartstein
13000,00
11310
Pat Fay
6000,00
5220
Susan Mavris
6500,00
5655
Hermann Baer
10000,00
8700
Shelley Higgins
12000,00
10440
William Gietz
8300,00
7221
Steven King
24000,00
20880
Neena Kochhar
17000,00
14790
13 .
2.
, , ,
hr.employees.
,
10000 .
. ,
.
23
John
Russell
14000,00
0,40
Janette
King
10000,00
0,35
Gerald
Cambrault
11000,00
0,30
Ellen
Abel
11000,00
0,30
Alberto
Errazuriz
12000,00
0,30
Karen
Partners
13500,00
0,30
Peter
Tucker
10000,00
0,30
Clara
Vishney
10500,00
0,25
Lisa
Ozer
11500,00
0,25
Harrison
Bloom
10000,00
0,20
Eleni
Zlotkey
10500,00
0,20
3.
,
3 .
.
, hr.employees
,
. ,
.
Ellen
Abel
ELLAB
Sundar
Ande
SUNAN
Mozhe
Atkinson
MOZAT
David
Austin
DAVAU
Hermann
Baer
HERBA
24
Shelli
Baida
SHEBA
Amit
Banda
AMIBA
Elizabeth
Bates
ELIBA
Sarah
Bell
SARBE
4.
, ,
employees hr
( salary).
,
24000
2100
6461.68
25
10 ( 1)
1.
2.
employees hr,
, 50.
3.
,
hr.employees,
,
( ).
,
Donald
OConnell
2600,00
21.06.1999
122
Grant
2600,00
13.01.2000
115
Whalen
4400,00
17.09.1987
263
Hartstein
13000,00
17.02.1996
162
Pat
Fay
6000,00
17.08.1997
144
Susan
Mavris
6500,00
07.06.1994
182
Baer
10000,00
07.06.1994
182
Higgins
12000,00
07.06.1994
182
Dougla
s
Jennife
r
Michae
l
Herma
nn
Shelley
26
Willia
m
Gietz
8300,00
07.06.1994
182
4.
, ,
employees hr
( salary).
,
24000
2100
6461.68
27
.
, .
1.1
, ,
(.. ).
1.2
,
(.. ).
1.3
, 10.
1.4
. .
1.5
3 4.
1.6
marks,
mark .
1.7
1.8
1.9
1.10
, 4.
28
.
1.1
1.2
1.3
1.4
1.5
1.6
1.7
1.8
1.9
1.10
29
.
, 1.1-1.5
Students
Lessons
Reqs ,
Exams , . , ,
Mark, , ,
(, , ).
1.1 , .
1.2 ,
.
1.3 ,
, .
1.4 , .
1.5 Exams Reqs,
Exams ( , ,
, ).
30
.
1.1
1)
2)
1.2
1.3
1.4
1)
2)
31
1.5
2.
.
: ,
, ,
Inline Views .
:
32
.
GROUP BY SELECT,
,
.
,
. GROUP BY ,
,
. Oracle ,
.
GROUP BY,
SELECT.
, ,
33
SELECT.
, SELECT,
GROUP BY. ,
.
HAVING
SELECT
HAVING
() , . HAVING
GROUP BY ,
GROUP BY. WHERE, HAVING
, WHERE
, Oracle , ,
HAVING.
WHERE,
HAVING,
, , ,
. - HAVING
WHERE .
, .
, ,
. (join)
, .
, .
,
( ). ,
Oracl , ,
.
34
FROM ( ) WHERE.
, ,
.
.
(equijoin),
()
,
.
.
,
FROM SELECT, ,
. (
) ,
, .
,
.
, ,
. , , , ,
.
(natural join),
. ,
( ).
35
, ANSI
SQL99, FROM
,
, .
INNER . ,
, . (
FROM, SELECT
WHERE, ORDER BY ..)
SELECT <column-list>
FROM <tablel> [<aliasl>] [INNER] JOIN <table2> [<alias2>]
ON {<tablel>|<aliasl>}.<join-columnl> = {<table2>|<alias2>}.<join-column2>;
FROM
( ) ON,
. "" ON
, ,
, .
, , ,
.
"" .
,
, ,
, .
. , ,
36
,
. ,
, Oracl
. (
, ,
.)
, ,
.
, ON.
SELECT <column-list>
FROM <tablel> [<aliasl>] NATURAL JOIN <table2> [<alias2>];
. , Oracle , .
, Oracle
, , .
,
, .
, .
(,
, ).
37
NULL,
.
:
,
. SELECT ,
:
NULL .
,
RIGHT OUTER JOIN
FROM. ,
, NULL
. ,
Oracle , ,
38
e ,
).
SQL FULL OUTER JOIN,
,
,
( ""
NULL ).
.
.
,
, , .
BETWEEN, <, <=, >, >=, =.
, ,
,
.
, SQL
( ).
SELECT, SQL.
, .
SQL,
: ,
39
SELECT;
FROM;
WHERE HAVING.
.
WHERE HAVING.
, ( )
IN, ANY ALL. , IN
,
. ANY
; ALL . ,
,
40
NOT
IN,
, .
:
26
1. , id (
hr.departments) , Seattle.
, :
DEPARTMENT_ID DEPARTMENT_NAME CITY
10
Administration
Seattle
30
Purchasing
Seattle
90
Execute
Seattle
:
1) C where
select department_id , department_name, city
from hr.departments d, hr.locations l
where d.location_id=l.location_id and city='Seattle';
2) join
select department_id , department_name, city
from hr.departments
natural inner JOIN hr.locations
where city='Seattle'
2. , , ,
, .
, :
41
DEPARTMENT_NAME CITY
COUNTRY_NAME REGION_NAME
Marketing
Toronto
Canada
IT
Americas
Americas
South
Shipping
San
United States
Americas
Francisco
:
1) where
select department_name, city, country_name, region_name
from hr.departments d, hr.locations l, hr.countries c, hr. regions r
where d.location_id=l.location_id and l.country_id=c.country_id and c.region_id=
r.region_id and region_name='Americas';
2) C join
select distinct department_name, city, country_name, region_name
from hr.departments d JOIN hr.locations l on d.location_id=l.location_id
JOIN hr.countries c on l.country_id=c.country_id
JOIN hr.regions r on c.region_id= r.region_id
where region_name='Americas'
3. , hr.employees ,
, ,
, 70.
, :
42
Lex
De Haan
17000
13.01.93
Bruce
Ernst
6000
21.05.91
Alexander
Hunold
9000
03.01.90
:
:
SELECT first_name AS "", last_name As "", salary AS "",
HIRE_DATE AS "_"
from hr.EMPLOYEES
WHERE HIRE_DATE < ALL(SELECT HIRE_DATE from hr.employees WHERE
DEPARTMENT_ID = 70)
4. ,
hr.employees ,
.
.
, :
Olson
2100
Shipping
8200
Markle
2200
Shipping
8200
Philtanker
2200
Shipping
8200
:
select e.last_name as , e.salary as , d.department_name as ,
b.maxsal as _
from hr.employees e, hr.departments d ,(select department_id, max(salary) maxsal
from hr.employees group by department_id) b
43
Sales
John
Russell
168000
Sales
David
Bernstein
114000
Sales
Louise
Doran
90000
:
:
or replace view primer as select department_name as , first_name as , last_name
as ,salary*12 as _
from hr.departments d, hr.employees e
where d.department_id=e.department_id;
:
select * from primer where ='Sales'
.
1 ( 2)
1
, employees
jobs hr. :
- ( employees);
- ( employees);
44
-
( jobs) ( employees).
, ,
.
Steven
King
President
16000
Lex
De Haan
Neena
Kochhar
Eleni
Zlotkey
Sales Manager
9580
Gerald
Cambrault
Sales Manager
9080
Alberto
Errazuriz
Sales Manager
8080
Karen
Partners
Sales Manager
6580
John
Russell
Sales Manager
6080
Sundita
Kumar
Sales Representative
5908
Banda
Sales Representative
5808
10 Amit
2
, employees
countries hr.
:
- ( employees);
- ( employees);
- , ( countries).
,
( 106 ).
, :
45
Ellen
Abel
United Kingdom
Sundar
Ande
United Kingdom
Mozhe
Atkinson
David
Austin
Hermann
Baer
Germany
Shelli
Baida
Amit
Banda
United Kingdom
Elizabeth
Bates
United Kingdom
Sarah
Bell
10
David
Bernstein
United Kingdom
3
employees jobs hr.
:
- ( employees);
- ( employees);
- ( salary employees);
- ( min_salary
jobs).
,
20 ( : 38 ).
, .
Steven
King
24000,00
20080
Neena
Kochhar
17000,00
15000
46
Lex
De Haan
17000,00
15000
David
Austin
4800,00
4000
Valli
Pataballa
4800,00
4000
Diana
Lorentz
4200,00
4000
Karen
Colmenares
2500,00
2500
Shelli
Baida
2900,00
2500
Sigal
Tobias
2800,00
2500
10
Guy
Himuro
2600,00
2500
4
, , ,
hr.employees,
( Sales department_name
departments). .
,
Michael
Hartstein
13000,00
Hermann
Baer
10000,00
Shelley
Higgins
12008,00
Steven
King
24000,00
Neena
Kochhar
17000,00
Lex
De Haan
17000,00
Alexander
Hunold
9000,00
Nancy
Greenberg
12008,00
Daniel
Faviet
9000,00
10
Den
Raphaely
11000,00
47
5
,
hr.employees.
, (
employee_id manager_id ).
.
, .
Steven
King
Neena
Kochhar
Lex
De Haan
Alexander
Hunold
Nancy
Greenberg
Den
Raphaely
Matthew
Weiss
Adam
Fripp
Payam
Kaufling
10
Shanta
Vollman
48
2 ( 2)
1
,
(hire_date) 01 2005 (
) (location_id) .
, .
JOB_ID
LOCATION_ID
SA_REP
2500
FI_ACCOUNT
1700
PU_CLERK
1700
SH_CLERK
1500
IT_PROG
1400
MK_REP
1800
ST_MAN
1500
ST_CLERK
1500
AD_VP
1700
10
SA_MAN
2500
2
, employees
countries hr.
:
- ( employees);
- ( employees);
- , ( regions).
,
( 106 ).
, :
49
Ellen
Abel
Europe
Sundar
Ande
Europe
Mozhe
Atkinson
Americas
David
Austin
Americas
Hermann
Baer
Europe
Shelli
Baida
Americas
Amit
Banda
Europe
Elizabeth
Bates
Europe
Sarah
Bell
Americas
10
David
Bernstein
Europe
3
, ,
, .
, :
Kaufling
01.05.2003
King
17.06.2003
Raphaely
07.12.2002
King
17.06.2003
De Haan
13.01.2001
King
17.06.2003
Greenberg
17.08.2002
Kochhar
21.09.2005
Higgins
07.06.2002
Kochhar
21.09.2005
Baer
07.06.2002
Kochhar
21.09.2005
Mavris
07.06.2002
Kochhar
21.09.2005
Whalen
17.09.2003
Kochhar
21.09.2005
50
Austin
25.06.2005
Hunold
03.01.2006
10
Faviet
16.08.2002
Greenberg
17.08.2002
4
, ,
, .
.
,
Mavris
Susan
6500,00
Vollman
Shanta
6500,00
Lee
David
6800,00
Popp
Luis
6900,00
Tuvault
Oliver
7000,00
Grant
Kimberely
7000,00
Sewall
Sarath
7000,00
Marvins
Mattea
7200,00
Bates
Elizabeth
7300,00
10
Smith
William
7400,00
5
,
(job_id) hr.employees.
,
( department_name='Executive').
.
, :
_
_
51
King
AD_PRES
Kochhar
AD_VP
De Haan
AD_VP
52
3 ( 2)
1
id
( hr.countries) ( regions),
.
:
COUNTRY_ID COUNTRY_NAME
REGION_NAME
US
Americas
CA
Canada
Americas
MX
Mexico
Americas
BR
Brazil
Americas
AR
Argentina
Americas
ML
Malaysia
Asia
JP
Japan
Asia
IN
India
Asia
CN
China
Asia
10
AU
Australia
Asia
11
SG
Singapore
Asia
2
, , ,
2006 .
.
:
Hire_date Job_title
53
Street_adress
1
Jean
Fleaur
23.02.200
6
Shipping Clerk
Julia
Dellinge 24.06.200
r
6
Shipping Clerk
Walsh
24.04.200
6
Shipping Clerk
McCain
01.07.200
6
Shipping Clerk
07.03.200
6
Accountant
2004 Charade Rd
Randall
Matos
15.03.200
6
Stock Clerk
Gates
11.07.200
6
Shipping Clerk
Feeney
23.05.200
6
Shipping Clerk
Himuro
15.11.200
6
Purchasing Clerk
2004 Charade Rd
Olsen
30.03.200
6
Sales
Representative
2
3
Alana
4
Samuel
5
6
7
Timothy
8
Kevin
9
Guy
1
0
Christopher
3
employees jobs hr.
:
- ( employees);
- ( employees);
- ( salary employees);
54
-
jobs).
( min_salary
,
5 ( : 12 ).
, .
Donald
OConnell
2600
2500
Douglas
Grant
2600
2500
Diana
Lorentz
4200
4000
Guy
Himuro
2600
2500
Karen
Colmenares
2500
2500
TJ
Olson
2100
2008
Eleni
Zlotkey
10500
10000
Amit
Banda
6200
6000
Sundita
Kumar
6100
6000
10
Charles
Johnson
6200
6000
4
, ,
, .
( : 51
). ,
Abel
Ellen
11000
Baer
Hermann
10000
Bates
Elizabeth
7300
55
Bernstein
David
9500
Bloom
Harrison
10000
Cambrault
Gerald
11000
Cambrault
Nanette
7500
Chen
John
8200
De Haan
Lex
17000
10
Doran
Louise
7500
5
, , ,
( job_id)
hr.employees. ,
.
hr.jobs
( min_salary). .
,
Karen
Colmenares
PU_CLERK
2500,00
Martha
Sullivan
SH_CLERK
2500,00
Randall
Perkins
SH_CLERK
2500,00
56
4 ( 2)
1
( hr.employees) ( hr.departments)
IT Sales ( : 39 ).
:
FIRST_NAME
LAST_NAME
DEPARTMENT_NAME
Alexander
Hunold
IT
Bruce
Ernst
IT
David
Austin
IT
Valli
Pataballa
IT
Diana
Lorentz
IT
John
Russell
Sales
Karen
Partners
Sales
Alberto
Errazuriz
Sales
Gerald
Cambrault
Sales
10
Eleni
Zlotkey
Sales
2
, , ,
10000 ( :
15 ).
.
:
57
Clara
Vishney
10500
Sales
SA_REP
Eleni
Zlotkey
10500
Sales
SA_MAN
Gerald
Cambrault
11000
Sales
SA_MAN
Den
Raphaely
11000
Purchasing
PU_MAN
Ellen
Abel
11000
Sales
SA_REP
Lisa
Ozer
11500
Sales
SA_REP
Alberto Errazuriz
12000
Sales
SA_MAN
Shelley
Higgins
12008
Accounting
AC_MGR
Nancy
Greenberg
12008
Finance
FI_MGR
10
Michael Hartstein
13000
Marketing
MK_MAN
3
employees jobs hr.
:
- ( employees);
- ( employees);
- ( salary employees);
- ( min_salary
jobs).
,
50 ( : 76 ).
, .
Donald
OConnell
2600
2500
Douglas
Grant
2600
2500
Jennifer
Whalen
4400
3000
58
Michael
Hartstein
13000
9000
Pat
Fay
6000
4000
Shelley
Higgins
12008
8200
Steven
King
24000
20080
Neena
Kochhar
17000
15000
Lex
De Haan
17000
15000
10
Bruce
Ernst
6000
4000
4
, ,
, .
( : 56
). ,
:
Olson
TJ
2100
Philtanker
Hazel
2200
Markle
Steven
2200
Landry
James
2400
Gee
Ki
2400
Perkins
Randall
2500
Colmenares
Karen
2500
Patel
Joshua
2500
Marlow
James
2500
10
Vargas
Peter
2500
59
5
, , ,
( job_id)
hr.employees. ,
.
hr.jobs
( min_salary). .
, :
Karen
Colmenares
PU_CLERK
2500
Martha
Sullivan
SH_CLERK
2500
Randall
Perkins
SH_CLERK
2500
60
5 ( 2)
1
( hr.employees) ( hr.jobs) ,
(
5 ).
:
FIRST_NAME
LAST_NAME
JOB_TITLE
Alexander
Hunold
Programmer
Bruce
Ernst
Programmer
David
Austin
Programmer
Valli
Pataballa
Programmer
Diana
Lorentz
Programmer
2
,
shipping finance (
51 ).
:
Donald
OConnell
Shipping
Douglas
Grant
Shipping
Nancy
Greenberg
Finance
Daniel
Faviet
Finance
John
Chen
Finance
Ismael
Sciarra
Finance
61
Jose Manuel
Urman
Finance
Luis
Popp
Finance
Matthew
Weiss
Shipping
10
Adam
Fripp
Shipping
3
employees jobs hr.
:
- ( employees);
- ( employees);
- ( salary employees);
- ( min_salary
jobs).
,
2
( : 3 ).
, :
Hermann
Baer
10000
4500
Alexander
Hunold
9000
4000
Daniel
Faviet
9000
4200
4
, ,
, .
,
10
Faviet
16.08.2002
Greenberg
17.08.2002
62
Fay
17.08.2005
Hartstein
17.02.2004
Zlotkey
29.01.2008
King
17.06.2003
Cambrault
15.10.2007
King
17.06.2003
Errazuriz
10.03.2005
King
17.06.2003
Partners
05.01.2005
King
17.06.2003
Russell
01.10.2004
King
17.06.2003
Mourgos
16.11.2007
King
17.06.2003
Vollman
10.10.2005
King
17.06.2003
Fripp
10.04.2005
King
17.06.2003
10
Weiss
18.07.2004
King
17.06.2003
5
, , ,
( job_id)
hr.employees. ,
.
hr.jobs
( max_salary). .
, :
Daniel
Faviet
FI_ACCOUNT
9000,00
63
6 ( 2)
1
( hr.employees) ,
3000.
.
:
FIRST_NAME
LAST_NAME
MIN_SALARY
Jennifer
Whalen
3000
Susan
Mavris
4000
Pat
Fay
4000
David
Austin
4000
Diana
Lorentz
4000
Bruce
Ernst
4000
Alexander
Hunold
4000
Valli
Pataballa
4000
William
Gietz
4200
10
Luis
Popp
4200
2
,
, ,
2006 .
:
Start_date
64
End_date
Kevin
Shipping
24.03.2006
31.12.2007
Kelly
Shipping
01.01.2007
31.12.2007
Girard
Shipping
24.03.2006
31.12.2007
Jean
Shipping
24.03.2006
31.12.2007
John
Shipping
24.03.2006
31.12.2007
Hazel
Shipping
24.03.2006
31.12.2007
Douglas
Shipping
01.01.2007
31.12.2007
William
Sales
01.01.2007
31.12.2007
Alberto
Sales
01.01.2007
31.12.2007
10
Anthony
Shipping
24.03.2006
31.12.2007
3
employees jobs hr.
:
- ( employees);
- ( employees);
- ( salary employees);
- ( max_salary
jobs).
,
2
( : 14 ).
, .
Donald
OConnell
2600
5500
Douglas
Grant
2600
5500
65
David
Austin
4800
10000
Valli
Pataballa
4800
10000
Diana
Lorentz
4200
10000
Guy
Himuro
2600
5500
Karen
Colmenares
2500
5500
James
Landry
2400
5000
Steven
Markle
2200
5000
10
TJ
Olson
2100
5000
4
, ,
, .
,
_
Kaufling
01.05.2003
King
17.06.2003
Raphaely
07.12.2002
King
17.06.2003
De Haan
13.01.2001
King
17.06.2003
Greenberg
17.08.2002
Kochhar
21.09.2005
Higgins
07.06.2002
Kochhar
21.09.2005
Baer
07.06.2002
Kochhar
21.09.2005
Mavris
07.06.2002
Kochhar
21.09.2005
Whalen
17.09.2003
Kochhar
21.09.2005
Austin
25.06.2005
Hunold
03.01.2006
10
Faviet
16.08.2002
Greenberg
17.08.2002
5
, , ,
( job_id)
66
hr.employees.
,
.
hr.jobs ( min_salary).
. ,
Karen
Colmenares
PU_CLERK
2500
Martha
Sullivan
SH_CLERK
2500
Randall
Perkins
SH_CLERK
2500
67
7 ( 2)
1
( hr.employees) ( hr.departments)
IT.
:
FIRST_NAME
LAST_NAME
DEPARTMENT_NAME
Alexander
Hunold
IT
Bruce
Ernst
IT
David
Austin
IT
Valli
Pataballa
IT
Diana
Lorentz
IT
2
, employees
countries hr.
:
- ( employees);
- ( employees);
- , ( countries).
, ,
.
,
( 35 ).
,
Susan
Mavris
United Kingdom
John
Russell
United Kingdom
68
Karen
Partners
United Kingdom
Alberto
Errazuriz
United Kingdom
Gerald
Cambrault
United Kingdom
Eleni
Zlotkey
United Kingdom
Peter
Tucker
United Kingdom
David
Bernstein
United Kingdom
Peter
Hall
United Kingdom
10
Christopher
Olsen
United Kingdom
3
, ,
, .
,
_
10
Faviet
16.08.2002
Greenberg
17.08.2002
Fay
17.08.2005
Hartstein
17.02.2004
Zlotkey
29.01.2008
King
17.06.2003
Cambrault
15.10.2007
King
17.06.2003
Errazuriz
10.03.2005
King
17.06.2003
Partners
05.01.2005
King
17.06.2003
Russell
01.10.2004
King
17.06.2003
Mourgos
16.11.2007
King
17.06.2003
Vollman
10.10.2005
King
17.06.2003
Fripp
10.04.2005
King
17.06.2003
10
Weiss
18.07.2004
King
17.06.2003
69
4
, ,
, .
( : 51
). ,
Abel
Ellen
11000
Baer
Hermann
10000
Bates
Elizabeth
7300
Bernstein
David
9500
Bloom
Harrison
10000
Cambrault
Gerald
11000
Cambrault
Nanette
7500
Chen
John
8200
De Haan
Lex
17000
10
Doran
Louise
7500
5
,
(job_id) hr.employees.
,
( department_name='Executive').
.
, .
_
King
AD_PRES
Kochhar
AD_VP
De Haan
AD_VP
70
8 ( 2)
1
( hr.employees), ,
2005 .
,
FIRST_NAME
LAST_NAME
START_DATE
END_DATE
Neena
Kochhar
21.09.1997
27.10.2001
Neena
Kochhar
28.10.2001
15.03.2005
Jennifer
Whalen
17.09.1995
17.06.2001
2
, employees
countries hr.
:
- ( employees);
- ( employees);
- , ( countries).
, ,
.
,
( 1 ).
,
Hermann
Baer
Germany
3
employees jobs hr.
:
- ( employees);
71
- (
employees);
- ( salary employees);
- ( min_salary
jobs).
,
20
( : 69 ).
, :
William
Gietz
8300
4200
Shelley
Higgins
12000
8200
Jennifer
Whalen
4400
3000
Ismael
Sciarra
7700
4200
John
Chen
8200
4200
Luis
Popp
6900
4200
7800
4200
Daniel
Faviet
9000
4200
Nancy
Greenberg
12000
8200
10
Susan
Mavris
6500
4000
4
, ,
, .
( : 56
). ,
:
72
Olson
TJ
2100
Philtanker
Hazel
2200
Markle
Steven
2200
Landry
James
2400
Gee
Ki
2400
Perkins
Randall
2500
Colmenares
Karen
2500
Patel
Joshua
2500
Marlow
James
2500
10
Vargas
Peter
2500
5
,
(job_id) hr.employees.
,
( department_name='Sales').
. 34 .
, :
Russell
SA_MAN
Partners
SA_MAN
Errazuriz
SA_MAN
Cambrault
SA_MAN
Zlotkey
SA_MAN
Tucker
SA_REP
Bernstein
SA_REP
Hall
SA_REP
Olsen
SA_REP
73
10
Cambrault
SA_REP
74
9 ( 2)
1
, ( hr.job_history),
2005.
:
FIEST_NAME LAST_NAME
START_DATE END_DATE
Jennifer
Whalen
01.07.2002
31.12.2006
Michael
Hartstein
17.02.2004
19.12.2007
Lex
De Haan
13.01.2001
24.07.2006
Den
Raphaely
24.03.2006
31.12.2007
Payam
Kaufling
01.01.2007
31.12.2007
Jonathon
Taylor
01.01.2007
31.12.2007
Jonathon
Taylor
24.03.2006
31.12.2006
2
, , ,
2004 .
.
:
Hire_date Job_title
Street_adress
Michael
Hartstein
McEwen
Sully
2
Allan
3
Patrick
75
Matthew Weiss
Janette
5
King
John
Russell
Sarah
Bell
Nandita
Sarchand
Ellen
Abel
Jason
Mallin
9
10
3
, ,
, .
,
_
Kaufling
01.05.2003
King
17.06.2003
Raphaely
07.12.2002
King
17.06.2003
De Haan
13.01.2001
King
17.06.2003
Greenberg
17.08.2002
Kochhar
21.09.2005
Higgins
07.06.2002
Kochhar
21.09.2005
Baer
07.06.2002
Kochhar
21.09.2005
Mavris
07.06.2002
Kochhar
21.09.2005
Whalen
17.09.2003
Kochhar
21.09.2005
Austin
25.06.2005
Hunold
03.01.2006
10
Faviet
16.08.2002
Greenberg
17.08.2002
76
4
, ,
, .
( : 51
). ,
Abel
Ellen
11000
Baer
Hermann
10000
Bates
Elizabeth
7300
Bernstein
David
9500
Bloom
Harrison
10000
Cambrault
Gerald
11000
Cambrault
Nanette
7500
Chen
John
8200
De Haan
Lex
17000
10
Doran
Louise
7500
5
, , ,
( job_id)
hr.employees. ,
.
hr.jobs
( min_salary). .
,
Karen
Colmenares
PU_CLERK
2500
Martha
Sullivan
SH_CLERK
2500
77
Randall
Perkins
SH_CLERK
78
2500
10 ( 2)
1
, ( hr.employees) ,
Sales Representative.
.
:
FIRST_NAME
LAST_NAME
SALARY
JOB_TITLE
Sundita
Kumar
6100
Sales Representative
Amit
Banda
6200
Sales Representative
Charles
Johnson
6200
Sales Representative
Sundar
Ande
6400
Sales Representative
David
Lee
6800
Sales Representative
Kimberely
Grant
7000
Sales Representative
Oliver
Tuvault
7000
Sales Representative
Sarath
Sewall
7000
Sales Representative
Mattea
Marvins
7200
Sales Representative
10
Elizabeth
Bates
7300
Sales Representative
2
,
shipping, finance, Human Resourses, Purchasing..
:
Donald
OConnell
Shipping
Douglas
Grant
Shipping
79
Nancy
Greenberg
Finance
Daniel
Faviet
Finance
John
Chen
Finance
Ismael
Sciarra
Finance
Jose Manuel
Urman
Finance
Luis
Popp
Finance
Den
Raphaely
Purchasing
10
Alexander
Khoo
Purchasing
3
, ,
, .
,
_
10
Faviet
16.08.2002
Greenberg
17.08.2002
Fay
17.08.2005
Hartstein
17.02.2004
Zlotkey
29.01.2008
King
17.06.2003
Cambrault
15.10.2007
King
17.06.2003
Errazuriz
10.03.2005
King
17.06.2003
Partners
05.01.2005
King
17.06.2003
Russell
01.10.2004
King
17.06.2003
Mourgos
16.11.2007
King
17.06.2003
Vollman
10.10.2005
King
17.06.2003
Fripp
10.04.2005
King
17.06.2003
10
Weiss
18.07.2004
King
17.06.2003
80
4
, ,
, .
.
,
Abel
Ellen
11000
Baer
Hermann
10000
Bates
Elizabeth
7300
Bernstein
David
9500
Bloom
Harrison
10000
Cambrault
Gerald
11000
Cambrault
Nanette
7500
Chen
John
8200
De Haan
Lex
17000
10
Doran
Louise
7500
5
,
hr.employees.
, (
employee_id manager_id ).
.
, .
Steven
King
Neena
Kochhar
Lex
De Haan
81
Alexander
Hunold
Nancy
Greenberg
Den
Raphaely
Matthew
Weiss
Adam
Fripp
Payam
Kaufling
10
Shanta
Vollman
2.
1
1. SELECT first_name AS "", last_name As "", Job_Title As
"",
(max_salary - salary) AS ""
FROM hr.employees, hr.jobs
WHERE (hr.employees.job_id = hr.jobs.JOB_ID)
ORDER BY (max_salary - salary) DESC
2
1. select distinct job_id, location_id
from hr.employees e, hr.departments d
where e.department_id=d.department_id and e.hire_date>'01.01.2005'
3
1. select c.COUNTRY_ID, c.COUNTRY_NAME, r.region_name
84
4
1. select e.first_name, e.last_name, d.department_name
from hr.EMPLOYEES e, hr.DEPARTMENTS d
where e.department_id=d.department_id
and d.department_name in ('IT', 'Sales')
5
1. select e.first_name, e.last_name, j.job_title
from hr.EMPLOYEES e, hr.JOBS j
where e.job_id=j.job_id
and j.job_title='Programmer'
87
WHERE hr.employees.job_id =
hr.jobs.min_salary*2
6
1. select e.first_name, e.last_name, j.min_salary
from hr.EMPLOYEES e, hr.JOBS j
where e.job_id=j.job_id
and j.min_salary>=3000
order by min_salary
7
1. select e.first_name, e.last_name, d.department_name
from hr.EMPLOYEES e, hr.DEPARTMENTS d
where e.department_id=d.department_id
and d.department_name='IT'
and hr.locations.location_id =
hr.departments.location_id
8
1. select e.first_name, e.last_name, j.start_date, j.END_DATE
from hr.EMPLOYEES e, hr.JOB_history j
where e.EMPLOYEE_ID=j.EMPLOYEE_ID
and j.END_DATE<'31.12.2005'
90
employees.last_name As "",
countries.country_name As ""
from hr.employees, hr.departments, hr.locations, hr.countries
where hr.departments.department_id = hr.employees.department_id
and hr.locations.location_id = hr.departments.location_id
and hr.countries.country_id = hr.locations.country_id and
countries.country_name='Germany'
9
1. select e.first_name, e.last_name, j.start_date, j.END_DATE
from hr.EMPLOYEES e, hr.JOB_history j
91
where
e.EMPLOYEE_ID=j.EMPLOYEE_ID
and j.END_DATE>'31.12.2005'
10
92
.
, .
2.1
2.2
, ,
.
2.3
, .
2.4
students.
, 0.
2.5
, .. ,
.
2.6
2.7
2.8
, .
2.9
, .
2.10 , .
94
2.1
2.1
2.2
2.3
2.3
2.4
2.5
2.5
2.6
2.7
95
2.8
2.9
2.9
2.10
2.10
2.10
96
.
, 2.1-2.6:
Students
Lessons
Reqs ,
Exams , . , ,
Mark, , ,
(, , ).
2.1
, .
2.2 , (..
, , ).
2.3 ID , ,
(ID ).
2.4
, .
2.5 , , ,
5.
2.6
, .
97
.
2.1
2.2
2.3
2.4
2.5
2.6
98
3.
.
.
, ,
. ,
, LIKE,
,
.
,
,
, , IP-
, .
.
.
,
,
.
. ,
REGEXP_INSTR,
REGEXP_SUBSTR
[, _
[,
[, _
[, _]]]])
.
_,
.
1,
. _ - 0,
; 1
, .
REGEXP_REPLACE ,
_,
--.
:
REGEXP_REPLACE(_,
[, _ [,
[,, [_]]]])
REGEXP_SUBSTR ,
.
:REGEXP_SUBSTR(_,
[, [,
[,_]]])
REGEXP_LIKE
:
REGEXP_LIKE(_, [, _])
(CHAR, VARCHAR2, CLOB,
NCHAR, NVARCHAR2 NCLOB, LONG). -
. _
,
,
.
100
2). ,
.
.
, , ,
.
,
.
2,
3.
2.
-c:
^ -
$ -
* -
? -
+ -
{m} - m , a{3} = aaa
{m,} - m , a{2,}= aa ,
aaa, aaaaa
{m,n} - m n
[ ] - , [abc]*=
ajhjh , bskjk , cjkjkjk
101
[^abc] -
| - , a|b
( ) -
\n - n , (abc)j\1=abcjabc
\ - (escape character ) ,
\d -
\D -
\w - - _
\s -
\S -
regexp_like( , )
regexp_instr( , )
regexp_substr( , )
regexp_replace( , , )
.
102
3.
1 ( 3)
. .. ,
, ,
(), , - .
. ,
.
__________________________________________________________________
2 ( 3)
. .. ,
- ,
.. ,
.
__________________________________________________________________
3 ( 3)
,
. (
)
__________________________________________________________________
4 ( 3)
, -,
, .
.
__________________________________________________________________
103
5 ( 3)
/ . ,
/.
6 ( 3)
,
. .
__________________________________________________________________
7( 3)
. (,
).
__________________________________________________________________
8 ( 3)
, .
__________________________________________________________________
9 ( 3)
. ,
, .
.
__________________________________________________________________
10 ( 3)
, .
__________________________________________________________________
104
4.
.
Oracle
Microsoft Access,
,
. , ,
Access ,
.
Oracle
,
. , Oracle,
.
. ,
, (
). "/", Oracle,
, ,
, .
,
,
CREATE USER.
. ,
""
:
, .
CREATE USER :
CREATE USER <_>
IDENTIFIED BY <>
[DEFAULT TABLESPACE <tablespace_name>]
[TEMPORARY TABLESPACE <tempspace_name>]
<_>
, <> . ,
105
.
SYSTEM, MANAGER.
,
SYSTEM.
, Oracle ,
.
SQL*Plus, Oracle, SYSTEM
, .
,
. . !
Ivanov Ivanov.
<Enter>, .
reate user Ivanov identified by Ivanov
Default tablespace users
Temporary tablespace temp
Quota 1m on users;
Ivanov ,
. , SYSTEM
, ,
. Oracle
CREATE SESSION.
.
,
SYSTEM.
,
:
( ),
,
-
. .
:
1.
.
106
IDENTIFIED
BY
<new_password>
,
. Oracle SQL*Plus
/SQL*Plus, PASSWORD. SQL*Plus
, .
, .
,
, SYSTEM. ""
.
107
DROP USER,
, .
DROP USER <_> [CASCADE]
column datatype - .
DEFAULT expr - .
column constraint - .
table constraint - .
TABLESPACE tablespace - .
CREATE TABLE.
. ALTER TABLE
:
*----- ALTER TABLE -- shema . tablename ----------------------------------------*
*----- ADD ( column datatype -- DEFAULT expr -- column constraint ) ----*
*----- MODIFY ( column datatype -- DEFAULT expr -- column constraint ) --*
*----- DROP COLUMN ( column ) -------------------------------------------------------*
*----- STORAGE storage options ---------------------------------------------------------*
:
ADD - .
108
datatype
column
DEFAULT expr - .
column constraint - .
MODIFY - .
o
column datatype - .
DEFAULT expr - .
column constraint - .
top(x)
<> , (
(views))
<> ,
<>, ,
where
<>
<>
:
UPDATE top(10) tbl_books SET price = 0 WHERE quantity = 0
OPTION (force GROUP, hash JOIN, force ORDER)
UPDATE Persons SET ADDress='Nissestien 67', City='Sandnes' WHERE LastName='Tjessem' AND FirstName='Jakob'
.
SELECT,
, SQL , , Oracle. ,
,
.
, .
, :
(,
, , SELECT
, )
,
, .
CREATE VIEW.
110
,
CREATE ANY VIEW.
CREATE VIEW Oracle
MATERIALIZED VIEW
Oracle, .
() :
CREATE [OR REPLACE] FUNCTION function_name
[ (parameter [,parameter]) ]
RETURN return_datatype
IS | AS
[declaration_section]
BEGIN
executable_section
[EXCEPTION
exception_section]
END [function_name];
, .
, :
1. IN .
.
2. OUT ,
.
3. IN OUT
.
111
() :
CREATE OR REPLACE Function FindCourse
( name_in IN varchar2 )
RETURN number
IS
cnumber number;
cursor c1 is
select course_number
from courses_tbl
where course_name = name_in;
BEGIN
open c1;
fetch c1 into cnumber;
if c1%notfound then
cnumber := 9999;
end if;
close c1;
RETURN cnumber;
EXCEPTION
WHEN OTHERS THEN
raise_application_error(-20001,An error was encountered ||SQLCODE|| -ERROR||SQLERRM);
END;
FindCourse. name_in
.
99999.
SQL :
select course_name, FindCourse(course_name) as course_id
from courses
where subject = Mathematics;
112
.
1 ( 4)
( ),
,
.
.
2 ( 4)
( ),
,
,
.
3 ( 4)
( ),
,
. .
4 ( 4)
( ),
,
(, ..).
.
113
5 ( 4)
( ),
,
.
.
6 ( 4)
( ),
,
,
.
7 ( 4)
( ),
,
-.
.
8 ( 4)
( ),
,
(, ..). .
114
.
, .
4.1 stud_mark, ,
, .
4.2 , 4.1,
123.
4.3
marks, ( 1).
4.1
4.2
4.3
115
5.
.
,
, .
,
Oracl
,
,
:
.
.
,
:
116
- ( resource)
- (321-)
-
- .
,
Oracle. ,
SELECT.
, FROM DUAL.
.
:
DROP FUNCTION <_>;
. 3.
3.
1000
1001
1002
:
,
,
1003
1004
1005
117
1006
1007
1008
()
3000
, ,
( ),
()
() ,
, , ,
,
( ):
3001
3011
3021
4000
,
,
,
( ), ()
() , ,
, ,
,
( )
() ,
,
,
( ), ()
()
,
, ,
,
( )
,
,
,
( ), ()
()
, ,
, ,
, (
)
():
118
4001
( )
, ()
4002
()
4003
( ),
4004
- ( ),
4005
()
() ,
.
4006
()
() ,
()
5000
5001
, ,
, ,
5002
5003
()
5004
5005
5006
5007
, - ,
,
( ) ,
,
,
,
, ()
,
119
6000
6001
3 7
() ,
,
7000
, ,
, :
7001
8000
8001
,
,
, ,
, ,
:
,
.
1 ( 5)
(321-) 1002.
id , ,
:
0- ;
1-.
2 ( 5)
(321-) 8001.
id , ,
:
0- ;
1-.
120
3 ( 5)
(321-) 5005.
id , ,
:
0- ;
1-.
4 ( 5)
(321-) 1005.
id , ,
:
0- ;
1-.
5 ( 5)
(321-) 5006.
id , ,
:
0- ;
1-.
6 ( 5)
(321-) 5002.
id , ,
:
0- ;
1-.
121
.
, .
5.1
.
5.1
6.
.
,
SQL-, .
, ,
, .
122
( DDL, DML). ,
, .
PL/SQL (block),
:
DECLARE
BEGIN
EXCEPTION
END;
.
.
.
(body) .
BEGIN EXCEPTION. EXCEPTION END,
.
CREATE IS AS -
:
CREATE OR REPLACE PROCEDURE [ ] IS or AS
.
BEGIN
EXCEPTION
END [ ]
123
. REPLACE ,
DROP PROCEDURE .
.
--
create sequence seq_otl
minvalue 1
maxvalue 999999999999999999999999999
start with 100
increment by 1
cache 20;
--
create table OPER_NAL
(
ID
NUMBER,
DOG
VARCHAR2(256),
DATA_DOG
DATE,
SUMMA_DOG
NUMBER,
DESCR
VARCHAR2(1024),
DATA_OP
DATE,
SUMMA_OP
VARCHAR2(256),
RASCH_PL
VARCHAR2(256),
BIC_PL
VARCHAR2(256),
NAIMEN_PL
VARCHAR2(256),
ADR_PL
VARCHAR2(256),
INN_PL
VARCHAR2(256),
RASCH_POL
VARCHAR2(256),
BIC_POL
VARCHAR2(256),
NAIMEN_POL VARCHAR2(256),
ADR_POL
VARCHAR2(256),
INN_POL
VARCHAR2(256)
)
--
create table OTLADKA
(
OTL_ID
NUMBER(38),
OTL_DATE DATE,
OTL_MES
VARCHAR2(1200)
)
124
--
o.inn_pl=pl
and o.inn_pol=pol;
commit;
--
insert into otladka
select naftita.seq_otl.nextval, sysdate, ' '||(select
count(*) from naftita.oper_nal)||' '
from dual;
commit;
--,
insert into otladka
select naftita.seq_otl.nextval, sysdate, ' '
from dual;
125
commit;
end;
.
SQL (Oracle, Microsoft SQL Server)
.
PL/SQL : .
, .
, .
, ,
.
, .
:
-CURSOR .
-OPEN ,
.
-FETCH
.
-CLOSE
%ISOPEN TRUE, .
%FOUND , , .
%NOTFOUND TRUE, .
%ROWCOUNT .
126
,
( ) :
1.
, ,
.
2.
3.
4.
:
CURSOR ( ) IS
SELECT FROM
WHERE
.
, .
:
DECLARE
-- 1. :
CURSOR get_orders IS
SELECT * FROM ORDERS;
-- 2.
CURSOR get_orders(Pord_num ORDERS.order_num%TYPE) IS
SELECT ORDER_DATE, MFR, AMOUNT FROM ORDERS
WHERE order_num = Pord_num;
-- 3.
CURSOR get_orders(Pord_num ORDERS.order_num%TYPE) IS
127
OPEN . :
OPEN - ( ) .
CLOSE. :
CLOSE -
,
. ,
,
. ,
, CLOSE,
,
PL/SQL!
, ! ,
.
, . ,
, - , .. .
.
FETCH. , .
,
. ,
, . FETCH
. :
FETCH - - INTO -
--
NUMBER,
SUMMA_OP VARCHAR2(256),
DESCR
VARCHAR2(1024),
INN_PL
VARCHAR2(256),
INN_POL
VARCHAR2(256)
)
--
create or replace procedure proc_oper_nal_cur(pl varchar2, pol varchar2)
is
CURSOR get_oper(c_pl naftita.operation.inn_pl%TYPE, c_pol
naftita.operation.inn_pol%TYPE) IS
select o.id, o.summa_op, o.descr, o.inn_pl, o.inn_pol
from naftita.operation o
where
o.inn_pl=c_pl
and o.inn_pol=c_pol;
v_id naftita.operation.id%TYPE;
v_sum naftita.operation.summa_op%TYPE;
v_descr naftita.operation.descr%TYPE;
v_inn_pl naftita.operation.inn_pl%TYPE;
v_inn_pol naftita.operation.inn_pol%TYPE;
begin
--,
insert into otladka
select naftita.seq_otl.nextval, sysdate, ' '
from dual;
commit;
--
delete from oper_nal2;
commit;
--
insert into otladka
select naftita.seq_otl.nextval, sysdate, ' '
from dual;
commit;
--
insert into otladka
130
select naftita.seq_otl.nextval,
'||pol
from dual;
commit;
--
open get_oper(pl,pol);
--
loop
fetch get_oper into v_id, v_sum, v_descr, v_inn_pl, v_inn_pol;
insert into oper_nal2 values(v_id, v_sum, v_descr, v_inn_pl, v_inn_pol);
commit;
exit when get_oper%NOTFOUND;
end loop;
--
insert into otladka
select naftita.seq_otl.nextval, sysdate, ' '||(select
count(*) from naftita.oper_nal2)||' '
from dual;
commit;
--
close get_oper;
--,
insert into otladka
select naftita.seq_otl.nextval, sysdate, ' '
from dual;
commit;
end;
: ,
.
,
.
. ,
insert,
.
.
PL/SQL
131
- PL/SQL,
, , . , .
- ; , ,
, , ( ),
.
:
CREATE OR REPLACE PACKAGE _ {IS AS}--
_
|_ |
|_
|_
__
_ |
END [_];
:
CREATE OR REPLACE PACKAGE BODY _ {IS AS}
__ | __ |
END [_];
.
, ,
, .
,
.
:
- . ,
,
132
. ,
WHERE
,
.
- ! ,
,
.
- .
,
, .
.
. .
,
,
. ,
.
.
, , ,
, .
,
PL/SQL.
,
( , GLOBAL
), ,
.
:
133
FROM emp
WHERE empno = theEmpNo;
RETURN(tmpSSN);
EXCEPTION
WHEN NO_DATA_FOUND THEN
RETURN(-1);
END;
--
FUNCTION hire_employee(theName VARCHAR2,
theDept NUMBER,
theSal NUMBER,
theDate DATE,
theSSN NUMBER) RETURN NUMBER IS
tmpEmpNo NUMBER;
BEGIN
IF (NOT next_empid%ISOPEN) THEN
OPEN next_empid;
END IF;
FETCH next_empid INTO tmpEmpNo;
-- ,
--
INSERT INTO EMP (empno,ename,deptno,sal,
hiredate,ssn,bonus)
VALUES(tmpEmpNo,theName,theDept,theSal,
theDate,theSSN,signingBonus);
RETURN(tmpEmpNo);
ECXEPTION
WHEN OTHERS THEN
RETURN(-1);
135
END;
--
PROCEDURE fire_employee(theEmpno NUMBER,
theReason VARCHAR2) IS
BEGIN
DELETE FROM emp
WHERE empno = theEmpno;
INSERT INTO terminations(empno,reason)
VALUES(theEmpno,theReason);
END;
--
PROCEDURE set_bonus(newValue NUMBER) IS
BEGIN
signingBonus := newValue;
END;
END LIB_HR;
: (
), ,
.
136
.
1 ( 6)
,
,
.
.
( ,
, , -
, ,
). ,
,
4.
2 ( 6)
,
,
.
.
( ,
, , -
, ,
). ,
, 4.
3 ( 6)
,
()
.
.
(
, ,
, - ,
137
, ). ,
,
4.
4 ( 6)
,
,
. .
(
, ,
, - ,
, ).
,
, 4.
5 ( 6)
,
()
.
.
( ,
, , -
, ,
). ,
, 4.
6 ( 6)
138
,
,
.
.
( ,
, , -
, ,
). ,
, 4.
7 ( 6)
, ()
.
.
( ,
, , - ,
, ).
,
, 4.
139
.
, .
6.1 , .
.
, ,
. ,
, .
result, (0
).
6.2 ,
,
( , ).
140
6.1
141
6.2
142