CALL
CALL in SQL is a command used to execute a stored procedure within a database. It runs the stored procedure exactly as it is designed without requiring the user to type the whole procedure each time it is needed. It helps to simplify and optimize database operations. The procedures to be called should already exist within the database structure.
Example
Output
Explanation
The CALL
command is used to execute a stored procedure in MySQL that has been defined previously. In this syntax, procedure_name()
is the name of the stored procedure to be executed. The result of the CALL
command indicates whether the procedure was executed successfully without any error. The message Query OK, 0 rows affected
denotes that the stored procedure was executed successfully.
Example
Output
Explanation
In the above code, a stored procedure named “GetEmployee” is created that takes one parameter and queries the “Employees” table for the row where the “EmployeeId” matches the input parameter. The “CALL” statement is then used to execute this stored procedure, providing “1” as the parameter. The output is as shown in the ‘Output’ section.