-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLab 10 - Stored Procedure.sql
45 lines (39 loc) · 1.11 KB
/
Lab 10 - Stored Procedure.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
--Nicholas Russell--
--Professor Labouseur--
--Database Systems Management--
--November 30, 2014--
--Lab 10: Stored Procedure--
--1. Write a function PreReqsFor(courseNum) where it returns the immediate prerequisites for the passed-in course number. --
create or replace function PreReqsFor(int, REFCURSOR) returns refcursor as
$$
declare
course int := $1;
resultset REFCURSOR := $2;
begin
open resultset for
select prereqnum
from prerequisites
where courseNum = course;
return resultset;
end;
$$
language plpgsql;
select PreReqsFor(308, 'results');
Fetch all from results;
--2. Write a function IsReReqFor(courseNum) which returns the courses for which the passed-in course number is an immediate pre-requisite.
create or replace function IsPreReqFor(int, REFCURSOR) returns refcursor as
$$
declare
prereq int := $1;
resultset REFCURSOR := $2;
begin
open resultset for
select coursenum
from prerequisites
where prereq = prereqnum;
return resultset;
end;
$$
language plpgsql;
select IsPreReqFor(220, 'results');
Fetch all from results;