0

I am searching the error for two hours, yet I can't find so far:

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

The above stored procedure works as if the link found, it will delete the row! If not, it will add and update the new link.

1 Answer 1

1

Change If EXIT to 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
Sign up to request clarification or add additional context in comments.

4 Comments

can i know what did i miss out?
"If exists" clause is used for checking if query is returning any rows. You had "If exit" in place of "if exists"
Oh man ! missing 's' and looking for 2 hour . Thanks a lot. Appreciate it.
@Achilles please mark my answer as correct if you feel it solved your problem

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.