-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path13.sql
187 lines (165 loc) · 4.41 KB
/
13.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
select * from pulpit;
select * from faculty;
select * from teacher;
select * from subject;
--1
declare procedure get_teachers(pcode teacher.pulpit%type)
is
cursor cs is select * from teacher where lower(pulpit) like lower('%' || pcode || '%') ;
buffer teacher%rowtype;
begin
open cs;
loop
fetch cs into buffer;
exit when cs%notfound;
dbms_output.put_line(buffer.teacher_name);
end loop;
close cs;
end;
begin
get_teachers('ÈÑèÒ');
end;
--2.
declare res number;
function get_num_teachers(pcode char) return number
is
buff number;
begin
select count(*) into buff from teacher where lower(pulpit) like lower('%' || pcode || '%') ;
return buff;
end get_num_teachers;
begin
res := get_num_teachers('ÈÑèÒ');
dbms_output.put_line('result = ' || res);
end;
--3.
declare procedure get_teachers(fcode pulpit.FACULTY%type)
is
cursor cs
is
select TEACHER.TEACHER_NAME, pulpit.FACULTY from teacher, pulpit
where teacher.pulpit = pulpit.pulpit and lower(pulpit.faculty) like lower('%' || fcode || '%');
tname teacher.TEACHER_NAME%type;
fname pulpit.faculty%type;
begin
open cs;
loop
fetch cs into tname, fname;
exit when cs%notfound;
dbms_output.put_line(tname);
end loop;
close cs;
end;
begin
get_teachers('ÈÄèÏ');
end;
--
declare procedure GET_SUBJECTS(pcode pulpit.pulpit%type)
is
cursor cs is select * from subject where lower(pulpit) like lower('%' || pcode || '%') ;
buffer SUBJECT%rowtype;
begin
open cs;
loop
fetch cs into buffer;
exit when cs%notfound;
dbms_output.put_line(buffer.subject_name);
end loop;
close cs;
end;
begin
GET_SUBJECTS('ÈÑèÒ');
end;
--4.
declare
res number;
function get_num_teachers(fcode FACULTY.FACULTY%TYPE) return number
is
buff number;
begin
select count(*) into buff from teacher , pulpit
where teacher.pulpit = pulpit.pulpit and lower(pulpit.faculty) like lower('%' || fcode || '%');
return buff-2;
end get_num_teachers;
begin
res := get_num_teachers('ÈÄèÏ');
dbms_output.put_line('result = ' || res);
end;
declare
res number;
function get_num_subjects(pcode pulpit.pulpit%TYPE) return number
is
buff number;
begin
select count(*) into buff from subject where lower(pulpit) like lower('%' || pcode || '%');
return buff;
end get_num_subjects;
begin
res := get_num_subjects('ÒË');
dbms_output.put_line('result = ' || res);
end;
--5. Ðàçðàáîòàéòå ïàêåò TEACHERS
CREATE OR REPLACE PACKAGE TEACHERS IS
PROCEDURE get_teachers(pcode teacher.pulpit%type);
procedure GET_SUBJECTS(pcode pulpit.pulpit%type);
function get_num_teachers(fcode FACULTY.FACULTY%TYPE) return number;
function get_num_subjects(pcode pulpit.pulpit%TYPE) return number;
END;
CREATE OR REPLACE PACKAGE BODY TEACHERS IS
PROCEDURE get_teachers(pcode teacher.pulpit%type) IS
cursor cs is select * from teacher where lower(pulpit) like lower('%' || pcode || '%') ;
buffer teacher%rowtype;
begin
open cs;
loop
fetch cs into buffer;
exit when cs%notfound;
dbms_output.put_line(buffer.teacher_name);
end loop;
close cs;
end;
procedure GET_SUBJECTS(pcode pulpit.pulpit%type)
IS
cursor cs is select * from subject where lower(pulpit) like lower('%' || pcode || '%') ;
buffer SUBJECT%rowtype;
begin
open cs;
loop
fetch cs into buffer;
exit when cs%notfound;
dbms_output.put_line(buffer.subject_name);
end loop;
close cs;
end;
function get_num_teachers(fcode FACULTY.FACULTY%TYPE) return number
is
buff number;
begin
select count(*) into buff from teacher , pulpit
where teacher.pulpit = pulpit.pulpit and lower(pulpit.faculty) like lower('%' || fcode || '%');
return buff-2;
end get_num_teachers;
function get_num_subjects(pcode pulpit.pulpit%TYPE) return number
IS
buff number;
begin
select count(*) into buff from subject where lower(pulpit) like lower('%' || pcode || '%');
return buff;
end get_num_subjects;
END TEACHERS;
--6.
declare
res number;
res2 number;
BEGIN
dbms_output.put_line('*****TEACERS*****');
TEACHERS.get_teachers('ÈÑèÒ');
dbms_output.put_line('*****SUBJECTS*****');
TEACHERS.get_subjects('ÈÑèÒ');
dbms_output.put_line('*****COUNT OF TEACERS*****');
res := TEACHERS.get_num_teachers('ÈÄèÏ');
dbms_output.put_line(res);
dbms_output.put_line('*****COUNT OF SUBJECTS*****');
res2 := TEACHERS.get_num_subjects('ÒË');
dbms_output.put_line(res2);
END;