-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBBMS_plsql.sql
103 lines (82 loc) · 2.72 KB
/
BBMS_plsql.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
-- pl/sql commands
SET SERVEROUTPUT ON
DECLARE
cnt integer;
d_name Donar.donar_name%type;
d_blood Donar.blood_group%type;
d_place Donar.donar_address%type;
p_blood Patient.blood_group%type;
p_place Patient.patient_address%type;
BEGIN
-- given donar id,print name of the donar
select donar_name into d_name
from Donar where donar_id = 101;
dbms_output.put_line('The name is : ' || d_name);
--exception
--when others then
--dbms_output.put_line('invalid id');
dbms_output.put_line('--------------');
-- print names of all the donars
cnt := 101;
while cnt<=110
loop
select donar_name into d_name
from Donar where donar_id = cnt;
dbms_output.put_line('The name is : ' || d_name);
cnt:=cnt+1;
end loop;
dbms_output.put_line('--------------');
--desired donar for a particular blood group and place
cnt := 101;
while cnt<=110
loop
select donar_name into d_name
from Donar where donar_id = cnt;
select blood_group into d_blood
from Donar where donar_id = cnt;
select donar_address into d_place
from Donar where donar_id = cnt;
if (d_blood = 'A+' and d_place = 'Dhaka') then
dbms_output.put_line('Desired donar : ' || cnt ||' '||d_name||' '||d_blood||' '||d_place);
end if;
cnt:=cnt+1;
end loop;
dbms_output.put_line('--------------');
-- donar available for a particular patient (anywhere)
select blood_group into p_blood
from Patient where patient_id = 1002;
cnt := 101;
while cnt<=110
loop
select donar_name into d_name
from Donar where donar_id = cnt;
select blood_group into d_blood
from Donar where donar_id = cnt;
select donar_address into d_place
from Donar where donar_id = cnt;
if (d_blood = p_blood) then
dbms_output.put_line('Desired donar : ' || cnt ||' '||d_name||' '||d_blood||' '||d_place);
end if;
cnt:=cnt+1;
end loop;
dbms_output.put_line('--------------');
-- donar available for a particular patient (in the same place)
select blood_group into p_blood
from Patient where patient_id = 1002;
select patient_address into p_place
from Patient where patient_id = 1002;
cnt := 101;
while cnt<=110
loop
select donar_name into d_name
from Donar where donar_id = cnt;
select blood_group into d_blood
from Donar where donar_id = cnt;
select donar_address into d_place
from Donar where donar_id = cnt;
if (d_blood = p_blood and d_place = p_place) then
dbms_output.put_line('Desired donar : ' || cnt ||' '||d_name||' '||d_blood||' '||d_place);
end if;
cnt:=cnt+1;
end loop;
END;