mysql DELIMITER mysql DROP PROCEDURE IF EXISTS all_authors mysql CREAT

 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
mysql> DELIMITER |
mysql> DROP PROCEDURE IF EXISTS all_authors |
mysql> CREATE PROCEDURE all_authors()
-> BEGIN
-> SELECT DISTINCT author as "Авторы книг" FROM books ORDER BY author;
-> END;
-> |
mysql> DELIMITER ;
mysql> CALL all_authors();
mysql> CREATE PROCEDURE books_by_publisher(IN pub VARCHAR(40))
-> BEGIN
-> SELECT id, title
-> FROM books
-> WHERE publisher = pub
-> ORDER BY id;
-> END;
-> |
mysql> DELIMITER ;
mysql> CALL books_by_publisher('Питер');
mysql> CALL books_by_publisher('Вильямс');
mysql> DROP PROCEDURE IF EXISTS books_count_by_publisher |
mysql> CREATE PROCEDURE books_count_by_publisher(IN pub VARCHAR(40))
-> BEGIN
-> SELECT COUNT(*)
-> FROM books
-> WHERE publisher = pub;
-> END;
-> |
mysql> DELIMITER ;
mysql> CALL books_count_by_publisher('Вильямс');
mysql> DELIMITER |
mysql> DROP PROCEDURE IF EXISTS world_country_by_code |
mysql> CREATE PROCEDURE world_country_by_code(IN code VARCHAR(40))
-> BEGIN
-> SELECT Name FROM country WHERE country.Code = code;
-> END;
-> |
mysql> DELIMITER ;
mysql> call world_country_by_code('AFG');
mysql> DELIMITER |
mysql> DROP PROCEDURE IF EXISTS world_code_by_country |
mysql> CREATE PROCEDURE world_code_by_country(IN country VARCHAR(40))
-> BEGIN
-> SELECT Code FROM country WHERE country.Name = country;
-> END;
-> |
mysql> DELIMITER ;
mysql> call world_code_by_country('Angola');