MySQL用分隔符创建存储过程语法

2021-11-20 00:00:00 sql mysql stored-procedures

我正在尝试使用这样的分隔符在 MySQL 中创建一个存储过程:

I am trying to create a stored procedure in MySQL using a delimiter like this:

use am;

DELIMITER $$

CREATE PROCEDURE addfields()
BEGIN
  DECLARE done INT DEFAULT FALSE;
  DECLARE acc INT(16);
  DECLARE validId INT DEFAULT 0;

END $$

DELIMITER ;

它给了我一个错误:

#1304 - PROCEDURE addfields already exists

使用分隔符创建存储过程并在它首先存在时删除它的正确语法是什么?

What is the proper syntax for making a stored procedure with a delimiter and dropping it if it exists first?

推荐答案

这里是带有分隔符和如何调用的示例 MYSQL 存储过程..

Here is the sample MYSQL Stored Procedure with delimiter and how to call..

DELIMITER $$

DROP PROCEDURE IF EXISTS `sp_user_login` $$
CREATE DEFINER=`root`@`%` PROCEDURE `sp_user_login`(
  IN loc_username VARCHAR(255),
  IN loc_password VARCHAR(255)
)
BEGIN

  SELECT user_id,
         user_name,
         user_emailid,
         user_profileimage,
         last_update
    FROM tbl_user
   WHERE user_name = loc_username
     AND password = loc_password
     AND status = 1;

END $$

DELIMITER ;

并调用,mysql_connection 规范和

and call by, mysql_connection specification and

$loginCheck="call sp_user_login('".$username."','".$password."');";

它将返回程序的结果.

相关文章