MySQL中的存储过程语法错误

时间:2016-06-14 07:31:28

标签: mysql stored-procedures

我正在搜索错误两个小时,但到目前为止我找不到:

CREATE DEFINER=`root`@`localhost` PROCEDURE `insert_diffmod`
     (IN para_diffmod LONGTEXT, 
      IN para_link LONGTEXT)
BEGIN

IF EXIT (
    SELECT website_link FROM diffmod WHERE website_link=para_link
    )THEN 
    DELETE FROM diffmod WHERE website_link=para_link;

ELSE
    INSERT INTO diffmod(website_id,website_link)
    SELECT id,link
    FROM   site_html
    Where  link=para_link;

    UPDATE diffmod
    SET diffmod_content= para_diffmod
    where website_link = para_link;

END IF; 
END

上面的存储过程就好像找到链接一样,它会删除行!如果没有,它将添加和更新新链接。

1 个答案:

答案 0 :(得分:1)

如果EXIT改为IF EXISTS

CREATE DEFINER=`root`@`localhost` PROCEDURE `insert_diffmod`( 
IN para_diffmod LONGTEXT, 
IN para_link LONGTEXT)
BEGIN

IF EXISTS (
    SELECT website_link FROM diffmod WHERE website_link=para_link
    )THEN 
    DELETE FROM diffmod WHERE website_link=para_link;

ELSE
    INSERT INTO diffmod(website_id,website_link)
    SELECT id,link
    FROM   site_html
    Where  link=para_link;

    UPDATE diffmod
    SET diffmod_content= para_diffmod
    where website_link = para_link;

END IF; 
END