Answer: Creating a Stored Procedure
Find a detailed explanation for creating a stored procedure in SQL.
Solution
The solution is given below:
Press + to interact
-- Query with stored procedure named as GetAllEmployeesDELIMITER $$CREATE PROCEDURE GetAllEmployees ()BEGINSELECT * FROM Employees;END $$DELIMITER ;-- Execute the stored procedureCALL GetAllEmployees ();-- Uncomment the following statement to list all stored procedures in the database-- SHOW PROCEDURE STATUS WHERE DB = 'ProductSalesDB';
Code explanation
The explanation of the solution code is given below:
Line 2: The
DELIMITER $$
changes the statement delimiter to$$
so semicolons can be used within the procedure.Line 4: The
CREATE PROCEDURE
defines a stored procedure calledGetAllEmployees
.Lines 5–7: The
BEGIN
andEND
are used to define the body of the stored procedure. TheSELECT
statement fetches all the records in theEmployees
table.Line 9: The
DELIMITER ;
resets the statement delimiter back to the default semicolon (;
)....
Access this course and 1400+ top-rated courses and projects.