-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathPROCEDURES.txt
126 lines (110 loc) · 3.27 KB
/
PROCEDURES.txt
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
CREATE OR REPLACE FUNCTION GET_MOVIE_RATING (MID IN NUMBER, PID IN VARCHAR2, EML IN VARCHAR2)
RETURN NUMBER IS
R NUMBER DEFAULT -1;
BEGIN
SELECT RATING INTO R
FROM MOVIE_WATCH
WHERE MOVIE_ID = MID AND PROFILE_ID = PID AND EMAIL = EML;
RETURN R;
END;
/
CREATE OR REPLACE PROCEDURE GET_MOVIE_TIMESTAMP (MID IN NUMBER, PID IN VARCHAR2, EML IN VARCHAR2, WATCHED_UPTO OUT NUMBER) IS
BEGIN
SELECT MW.WATCHED_UPTO INTO WATCHED_UPTO
FROM MOVIE_WATCH MW
WHERE MW.MOVIE_ID = MID AND MW.PROFILE_ID = PID AND MW.EMAIL = EML;
IF WATCHED_UPTO = NULL THEN
WATCHED_UPTO := 0;
END IF;
EXCEPTION
WHEN NO_DATA_FOUND THEN
WATCHED_UPTO := 0;
END;
/
CREATE OR REPLACE PROCEDURE GET_EPISODE_TIMESTAMP (SID IN NUMBER, SEASON IN NUMBER,
EPISODE IN NUMBER, PID IN VARCHAR2, EML IN VARCHAR2, WATCHED_UPTO OUT NUMBER) IS
BEGIN
SELECT EW.WATCHED_UPTO INTO WATCHED_UPTO
FROM EPISODE_WATCH EW
WHERE EW.SHOW_ID = SID AND EW.PROFILE_ID = PID AND EW.EMAIL = EML
AND SEASON_NO = SEASON AND EPISODE_NO = EPISODE;
IF WATCHED_UPTO = NULL THEN
WATCHED_UPTO := 0;
END IF;
EXCEPTION
WHEN NO_DATA_FOUND THEN
WATCHED_UPTO := 0;
END;
/
CREATE
OR REPLACE PROCEDURE SET_MOVIE_TIMESTAMP ( MID IN NUMBER, PID IN VARCHAR2, EML IN VARCHAR2, WU IN NUMBER ) IS BEGIN
INSERT INTO MOVIE_WATCH ( MOVIE_ID, PROFILE_ID, EMAIL, WATCHED_UPTO )
VALUES
( MID, PID, EML, WU );
EXCEPTION
WHEN DUP_VAL_ON_INDEX THEN
UPDATE MOVIE_WATCH
SET WATCHED_UPTO = WU,
TIME = SYSDATE
WHERE
PROFILE_ID = PID
AND MOVIE_ID = MID
AND EMAIL = EML;
END;
/
CREATE
OR REPLACE PROCEDURE SET_EPISODE_TIMESTAMP ( SID IN NUMBER, SNO IN NUMBER, ENO IN NUMBER, PID IN VARCHAR2, EML IN VARCHAR2, WU IN NUMBER ) IS BEGIN
INSERT INTO EPISODE_WATCH ( SHOW_ID, SEASON_NO, EPISODE_NO, PROFILE_ID, EMAIL, WATCHED_UPTO )
VALUES
( SID, SNO, ENO, PID, EML, WU );
EXCEPTION
WHEN DUP_VAL_ON_INDEX THEN
UPDATE EPISODE_WATCH
SET WATCHED_UPTO = WU,
TIME = SYSDATE
WHERE
PROFILE_ID = PID
AND SHOW_ID = SID
AND EMAIL = EML
AND SEASON_NO = SNO
AND EPISODE_NO = ENO;
END;
/
CREATE OR REPLACE PROCEDURE SET_MOVIE_RATING (MID IN NUMBER, EML IN VARCHAR2, PID IN VARCHAR2, MRATING IN NUMBER) IS
BEGIN
INSERT INTO MOVIE_WATCH (MOVIE_ID, EMAIL, PROFILE_ID, RATING)
VALUES (MID, EML, PID, MRATING);
EXCEPTION
WHEN DUP_VAL_ON_INDEX THEN
UPDATE MOVIE_WATCH
SET RATING = MRATING
WHERE MOVIE_ID = MID AND PROFILE_ID = PID AND EMAIL = EML;
END;
/
CREATE OR REPLACE PROCEDURE SET_SHOW_RATING (SID IN NUMBER, EML IN VARCHAR2, PID IN VARCHAR2, SRATING IN NUMBER) IS
BEGIN
INSERT INTO SHOW_WATCH (SHOW_ID, EMAIL, PROFILE_ID, RATING)
VALUES (SID, EML, PID, SRATING);
EXCEPTION
WHEN DUP_VAL_ON_INDEX THEN
UPDATE SHOW_WATCH
SET RATING = SRATING
WHERE SHOW_ID = SID AND PROFILE_ID = PID AND EMAIL = EML;
END;
/
CREATE OR REPLACE PROCEDURE CHECK_VALIDATION(EML IN VARCHAR2) IS
BEGIN
UPDATE SUBSCRIPTION
SET RUNNING=0 , TOTAL_BILL = ROUND( ( MONTHS_BETWEEN(SYSDATE,START_DATE)) *BILL ,2)
WHERE EMAIL = EML AND END_DATE < SYSDATE;
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('NO DATA FOUND');
WHEN TOO_MANY_ROWS THEN
DBMS_OUTPUT.PUT_LINE('TOO MANY ROWS');
WHEN DUP_VAL_ON_INDEX THEN
DBMS_OUTPUT.PUT_LINE('DUPLICATE VALUE ON INDEX');
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('UNKNOWN ERROR');
END;
/