Use DECLARE Statement in Procedure

Use DECLARE Statement in Procedure is used to define variable and its data type.

Use DECLARE Statement in Procedure

Use DECLARE Statement in Procedure

     

Use DECLARE Statement in Procedure is used to define variable and its data type.

Understand with Example

The Tutorial illustrate an example from 'Use Declare Statement in Procedure'. To grasp this Example, we create a procedure 'abc'. The Query start with the BEGIN Section that include DECLARE statement which define a variable x ,y and z and data type is integer kind. The SET variable set the value of ' x' to 10 and 'y' to 20.The set z set the compute value of variable x and y respectively.

  select z :The select z return you the sum value of x and y variable in z.

 

Create Procedure

delimiter $$
create procedure abc()
BEGIN 
	DECLARE x int;
	DECLARE y int;
	DECLARE z int;
	SET x = 10;
	SET y = 20;
	set z = x+y;
	select z;
END$$
delimiter ;

Call Procedure

To invoke a procedure, we use call abc ( ).The below syntax show you to call procedure :

call abc()

Result

+------+
| z    |
+------+
| 30   |
+------+