`
xiatianyu_22
  • 浏览: 4110 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

how to create mysql stored procedure

 
阅读更多

  Launch the mysql client tool and type the following commands:

DELIMITER //

DROP PROCEDURE  IF EXISTS test.read_recordByIdttx //

   CREATE DEFINER=`root`@`localhost` PROCEDURE read_recordById (IN emp_id INT)

 

   BEGIN 

      SELECT * FROM STUDENT WHERE ID = emp_id; 

   END// 

 

DELIMITER ;

Let's examine the stored procedure in greater detail:

The first command is DELIMITER //, which is not related to the stored procedure syntax. The DELIMITER statement changes the standard delimiter which is semicolon to another. In this case, the delimiter is changed from semicolon to double-slashes. Why do we have to change the delimiter? Because we want to pass the stored procedure to the server as a whole rather than letting mysql tool interpret each statement at a time. Following the END keyword, we use the delimiter // to indicate the end of the stored procedure. The last command changes the delimiter back to the semicolon.

 

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics