mysql - Mysql 存储过程 BEGIN END

标签 mysql stored-procedures dbforge

我正在编写一个简单的存储过程来获取数据并将其输入表

CREATE DEFINER = 'gunsdb-3939c99d-COPY-39393fb6'@'%'
PROCEDURE `gunsdb-3939c99d-COPY-39393fb6`.sp_entity_save(IN p_entity_id INT, IN p_entity_type_id INT, IN p_title_id INT, IN p_first_name VARCHAR(255), IN p_last_name VARCHAR(255), IN p_street_line_1 VARCHAR(255), IN p_street_line_2 VARCHAR(255), IN p_street_line_3 VARCHAR(255), IN p_town VARCHAR(255), IN p_county VARCHAR(255), IN p_postcode VARCHAR(255), IN p_email VARCHAR(255), IN p_telephone INT, IN p_company_name VARCHAR(500), IN p_company_desc VARCHAR(500), IN p_website VARCHAR(500), IN p_rfd_number INT, IN p_issuing_force VARCHAR(255), IN p_concent VARCHAR(255))
BEGIN    
INSERT INTO tbl_entity (
entity_id,
entity_type_id,
title_id,
first_name,
last_name,
street_line_1,
street_line_2,
street_line_3,
town,county,
postcode,
email,
telephone,
company_name,
company_desc,
website,
rfd_number,
issuing_force,
concent
)

VALUES
(
p_entity_id,
p_entity_type_id,
p_title_id,
p_first_name,
p_last_name,
p_street_line_1 , 
p_street_line_2,
p_street_line_3 ,
p_town, @county , 
p_postcode,
p_email ,
p_telephone,
p_company_name , 
p_company_desc, 
p_website, 
p_rfd_number , 
p_issuing_force , 
p_concent
)
ON DUPLICATE KEY UPDATE
    entity_type_id = p_entity_type_id, 
    title_id = p_title_id, 
    first_name = p_first_name, 
    last_name = p_last_name, 
    street_line_1 = p_street_line_1,
    street_line_2 = p_street_line_2,
    street_line_2 = p_street_line_2,
    town = p_town,
    county= p_county,
    postcode = p_postcode,
    email = p_email,
    telephone = p_telephone,
    company_name = p_company_name,
    company_desc = p_company_desc,
    website = p_website,
    rfd_number = p_rfd_number,
    issuing_force = p_issuing_force,
    concent = p_concent  
END

上面抛出了一个错误,但是一旦删除 BEGIN 和 END,它就工作正常,我不明白为什么。

我尝试添加 DELIMITER 但似乎遇到了同样的问题:

You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'END' at line 77 SQL1.sql 77 3

我正在使用 dbforge,但我也在 Navicat 中尝试过并遇到了同样的问题。

最佳答案

您使用了正确的分隔符吗?在您的代码中,插入末尾没有分隔符。
您应该在插入末尾使用分隔符。

delimiter //
CREATE 
PROCEDURE sp_entity_save(IN p_entity_id INT, IN p_concent VARCHAR(255))
BEGIN    
INSERT INTO tbl_entity (
entity_id,
concent
)
VALUES
(
p_entity_id,
p_concent
)
ON DUPLICATE KEY UPDATE
    -- delimiter here
    concent = p_concent;
-- delimiter here
END //

关于mysql - Mysql 存储过程 BEGIN END,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55068435/

相关文章:

java - 通过 JDBC 将可变长度的外键列表作为参数传递给存储过程,然后使用这些列表将行插入表中

mysql - 如何从 Rails 调用 MySQL 存储过程?

mysql - 如何在报告中获得条件输出?

mysql - 意外符号 'NONE' 存档引擎 - MariaDB DBForge

mysql - 使用 count 将两个表连接在一起

mysql - 在 mySQL 中从一行生成多行

MySQL在日期时间字段中创建具有唯一年月日键的表

sql-server - 存储过程适用于 SQL Server 2000,但不适用于 SQL Server 2008R2

mysql - BASH - 使用存储在数组中的参数执行 mysql 命令

mysql - 从 Windows 客户机(dbforge 查询生成器)访问主机中的 mysql 数据库(mamp)