-
Notifications
You must be signed in to change notification settings - Fork 0
/
Procedures.txt
59 lines (46 loc) · 1.41 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
GET ALL MOVIES WITH RUNTIME GREATER THAN THE GIVEN VALUE
DELIMITER //
CREATE PROCEDURE MovieFromRuntime(IN rt SMALLINT)
BEGIN
SELECT Title
FROM movies
WHERE Runtime =
ANY (
SELECT Runtime
FROM movies
WHERE Runtime>rt
);
END //
DELIMITER ;
COUNT NUMBER OF MALE AND FEMALE FROM PEOPLE
DELIMITER //
CREATE PROCEDURE CountGender()
BEGIN
DECLARE Male INT DEFAULT 0;
DECLARE Female INT DEFAULT 0;
SELECT COUNT(PID) INTO Male FROM people WHERE Gender = 'M';
SELECT COUNT(PID) INTO Female FROM people WHERE Gender = 'F';
SELECT Male, Female;
END //
DELIMITER ;
INSERT INTO CAST TABLE, EXCEPTION IF DUPLICATE KEY
DELIMITER //
CREATE PROCEDURE InsertCast(IN mi INT, IN pi INT, IN cn VARCHAR(255))
BEGIN
DECLARE CONTINUE HANDLER FOR 1062
SELECT CONCAT('Duplicate Keys (',mi,',',pi,') Found') AS Error;
INSERT INTO cast VALUES (mi, pi, cn);
END //
DELIMITER ;
INSERT INTO REVIEWS WITH VALID RATING VALUE
DELIMITER //
CREATE PROCEDURE AddReview(IN ui INT, IN mi INT, IN d date, IN s tinyint, IN c VARCHAR(1023))
BEGIN
IF(s > 5) THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = 'Rating should be less than or equal to 5';
ELSE
INSERT INTO Reviews VALUES (ui, mi, d, s, c);
END IF;
END //
DELIMITER ;