简体   繁体   中英

Error on creating a stored procedure in MySQL, Error#1064

I'm having a hard time creating a stored procedure. I have tried altering some things according to other entries on stack overflow but it did not help.

select version(); returns 5.7.31-0ubuntu0.16.04.1 incase that helps.

Here's the query:

DELIMITER $$
CREATE
PROCEDURE forceSubscribeToNode(IN node_id_var INT)
BEGIN
  INSERT
INTO
  xf_forum_watch(
    user_id,
    node_id,
    notify_on,
    send_alert,
    send_email
  )
SELECT
  user_id,
  node_id_var AS node_id,
  "thread" AS notify_on,
  1 AS send_alert,
  1 AS send_email
FROM
  xf_user
WHERE
  user_group_id NOT IN(
      1, 18, 40
  )
  ON DUPLICATE KEY
UPDATE
  send_alert = 1,
  send_email = 1,
  notify_on = CASE WHEN notify_on IS NULL OR notify_on = '' THEN 'thread' ELSE notify_on END
END $$
DELIMITER ;

Here's the error:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'END' at line 30

(Line 18 is "send_email = 1,"

For context, search engines and future reference:

This will be used for the forum software Xenforo 2.1 to force subscribe users to certain nodes like categories and sub-forums.

So it seems I forgot to add a ; with a space before after the first END

DELIMITER $$
CREATE
PROCEDURE forceSubscribeToNode(IN node_id_var INT)
BEGIN
  INSERT
INTO
  xf_forum_watch(
    user_id,
    node_id,
    notify_on,
    send_alert,
    send_email
  )
SELECT
  user_id,
  node_id_var AS node_id,
  "thread" AS notify_on,
  1 AS send_alert,
  1 AS send_email
FROM
  xf_user
WHERE
  user_group_id NOT IN(
      1, 18, 40
  )
  ON DUPLICATE KEY
UPDATE
  send_alert = 1,
  send_email = 1,
  notify_on = CASE WHEN notify_on IS NULL OR notify_on = '' THEN 'thread' ELSE notify_on END ;
END $$

DELIMITER ;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM