-
Notifications
You must be signed in to change notification settings - Fork 0
/
funkcje.sql
62 lines (60 loc) · 1.31 KB
/
funkcje.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
SET SERVEROUTPUT ON;
-- liczy albumy na podana litere, co wiecej powiedziec?
create or replace function licz_albumy(L char) return int
as
cursor C1 is select * from albumy;
vals albumy%ROWTYPE;
i int default 0;
begin
open C1;
fetch C1 into vals;
while C1%found loop
if upper(substr(vals.nazwa,1,1)) = upper(L) then
i:=i+1;
DBMS_OUTPUT.PUT_LINE(vals.nazwa);
end if;
fetch C1 into vals;
end loop;
close C1;
return i;
end;
/
-- liczy albumy podanego wykonawcy
create or replace function licz_albumy_wyk(nazwa varchar) return int
as
cursor CA is select * from albumy;
cursor CZ is select * from zespol;
zes zespol%ROWTYPE;
alb albumy%ROWTYPE;
idx integer default -1;
ilosc integer default 0;
not_found exception;
begin
open CZ;
fetch CZ into zes;
while CZ%found loop
if upper(nazwa) = upper(zes.nazwa) then
idx:=zes.idzes;
exit;
end if;
fetch CZ into zes;
end loop;
close CZ;
if idx = -1 then
raise not_found;
end if;
open CA;
fetch CA into alb;
while CA%found loop
if alb.idwyk = idx then
ilosc:=ilosc+1;
end if;
fetch CA into alb;
end loop;
close CA;
return ilosc;
exception
when not_found then
RAISE_APPLICATION_ERROR(-20001, 'author not found');
end;
/