Skip to content

Commit befad17

Browse files
authored
Update Readme.md
1 parent 23adcf3 commit befad17

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

Chapter 10/Readme.md

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,48 @@ A Stored Procedure is a collection of pre-compiled SQL statements stored inside
6868

6969
The stored procedure is defined by wraping a SQL statements within the CREATE PROCEDURE statement. The stored procedure may contain a conditional statement like IF or CASE or the Loops. The stored procedure can also execute another stored procedure or a function that modularizes the code.
7070

71+
In MySQL, stored procedure execution is called "calling", and so the statement to execute a stored procedure is simply ***CALL***. CALL takes the name of the stored procedure and any parameters that need to be passed on to it.
7172

72-
**Syntax:**
73+
**Syntax:** ***CREATE PROCEDURE***
7374
```
7475
CREATE PROCEDURE procedure_name ([parameter_1], [parameter_2], [parameter_3],.. )
7576
BEGIN
7677
SQL Queries..
7778
END
7879
```
7980

80-
In the syntax:
81+
In the syntax above:
8182
1. The name of the procedure must be specified after the CREATE PROCEDURE keyword
8283
2. After the name of the procedure, the list of parameters should be specified in the parenthesis. The parameter list must be comma-separated
8384
3. The SQL Queries and code must be written between BEGIN and END keywords
8485

86+
**Syntax:** ***CALL PROCEDURE***
87+
```
88+
CALL procedure_name(@parameter1, @parameter2);
89+
```
90+
91+
In the syntax above:
92+
1. The name of the procedure must be specified after the CALL keyword
93+
2. After the name of the procedure, the list of parameters should be specified in the parenthesis. The parameter list must be prefixed with @ and should be comma-separated.
94+
95+
**Example:**
96+
97+
Let's create a stored procedure, which will take film_id as input and will return all the details related to the film.
98+
99+
***1. Create Procedure:***
100+
101+
```sql
102+
DELIMITER //
103+
104+
CREATE PROCEDURE sp_GetMovies(sp_film_id int)
105+
BEGIN
106+
SELECT *
107+
FROM sakila.film
108+
WHERE film_id=sp_film_id;
109+
END //
110+
111+
DELIMITER ;
112+
```
113+
85114

115+
***1. Call Procedure:***

0 commit comments

Comments
 (0)