how to call a stored procedure mysql code example

Example 1: create stored procedure mysql

DELIMITER $$

CREATE PROCEDURE GetAllProducts()
BEGIN
	SELECT *  FROM products;
END $$

DELIMITER ;


-- Once you save the stored procedure, you can invoke it by using the CALL statement:

CALL GetAllProducts();

Example 2: mysql stored procedure

Syntax:
-------------------
CREATE [DEFINER = { user | CURRENT_USER }]          
PROCEDURE sp_name ([proc_parameter[,...]])          
[characteristic ...] routine_body    
proc_parameter: [ IN | OUT | INOUT ] param_name type    
type:          
Any valid MySQL data type    
characteristic:          
COMMENT 'string'     
| LANGUAGE SQL      
| [NOT] DETERMINISTIC      
| { CONTAINS SQL | NO SQL | READS SQL DATA 
| MODIFIES SQL DATA }      
| SQL SECURITY { DEFINER | INVOKER }    
routine_body:      
Valid SQL routine statement

Example
mysql> DELIMITER $$ ;
mysql> CREATE PROCEDURE student_details()
> SELECT * FROM student_details; $$
Query OK, 0 rows affected (0.00 sec)

Tags:

Sql Example