-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram9 FUNCTIONS.sql
More file actions
81 lines (51 loc) · 1.38 KB
/
Copy pathProgram9 FUNCTIONS.sql
File metadata and controls
81 lines (51 loc) · 1.38 KB
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
-- Developer: <Aaron>
--
-- Program #: <Programming Assignment Number 7>
--
-- File Name: <Program6-Anchor.sql>
--
-- Description:
-- <Using a FUNCTION to retrieve information and have the retrurn display a message.>
SET SERVEROUTPUT ON
Create or replace
Function MOVIE_STOCK
(movieid NUMBER)
RETURN VARCHAR2 is
info_string varchar2(150);
title mm_movie.movie_title%type;
quantity mm_movie.movie_qty%type;
BEGIN
SELECT movie_title,movie_qty INTO title, quantity FROM mm_movie WHERE movie_id=movieid;
IF (quantity >0) THEN
info_string:=title || ' is available : ' ||quantity || ' on the shelf';
END IF;
RETURN info_string;
EXCEPTION
WHEN NO_DATA_FOUND THEN
info_string:='Star Wars is not available:';
RETURN info_string;
END;
-- TEST --
SET SERVEROUTPUT ON
BEGIN
DBMS_OUTPUT.PUT_LINE(MOVIE_STOCK (2));
END;
/
SET SERVEROUTPUT ON
BEGIN
DBMS_OUTPUT.PUT_LINE(MOVIE_STOCK (3));
END;
/
SET SERVEROUTPUT ON
BEGIN
DBMS_OUTPUT.PUT_LINE(MOVIE_STOCK (20));
END;
/
-- Output
Function MOVIE_STOCK_SF compiled
Bladerunner is available : 3 on the shelf
PL/SQL procedure successfully completed.
Star Wars is available : 11 on the shelf
PL/SQL procedure successfully completed.
Star Wars is not available:
PL/SQL procedure successfully completed.