Saturday, September 6, 2014

Stored Procedure in MySQL

Stored Procedure Creation

DELIMITER //
 CREATE PROCEDURE <procedure-name>()
   BEGIN
   <query>
   END //
 DELIMITER ;

Syntax :-

The first command is DELIMITER //, which is not related to the stored procedure syntax. 
We use it as we want to pass the  stored procedure to the server as a whole rather than letting mysql tool to interpret each statement at a time.  Following the ENDkeyword, we use the delimiter // to indicate the end of the stored procedure. The last command ( DELIMITER;) changes the delimiter back to the standard one.

We use the CREATE PROCEDURE statement to create a new stored procedure. We specify the name of stored procedure after the CREATE PROCEDURE statement. 


The section between BEGIN and END is called the body of the stored procedure. We put the declarative SQL statements in the body to handle business logic.

No comments:

Post a Comment