131k views
0 votes
How can you create a stored procedure in MySQL?

a) Using the CREATE FUNCTION statement
b) Using the CREATE PROCEDURE statement
c) Using the DECLARE PROCEDURE statement
d) Using the ADD PROCEDURE statement

User Woryzower
by
7.6k points

1 Answer

6 votes

Final answer:

To create a stored procedure in MySQL, one must use the CREATE PROCEDURE statement, set a custom delimiter, define the procedure, and reset the delimiter to avoid conflicts during execution.

Step-by-step explanation:

To create a stored procedure in MySQL, you would use the CREATE PROCEDURE statement. This instruction allows you to define a set of SQL statements that you can save and execute at a later time. Here is a basic example of how you might define a stored procedure:

DELIMITER //
CREATE PROCEDURE SimpleProcedure()
BEGIN
SELECT 'Hello, World!';
END //
DELIMITER ;

This example sets a new delimiter, defines a procedure called SimpleProcedure that simply selects a string, and then resets the delimiter. It's critical to change the delimiter when creating stored procedures to avoid conflicts with semicolons that are part of the procedure definition.

User Ewerybody
by
8.9k points