[英]MySQL Error 1064: Creating a procedure
我正在修改我的程序。 由於我切換到另一個Webspace提供程序,並且它們不允許使用SQL-Trigger,因此我需要在過程中執行以下操作:
在為招聘創建評論后,必須更新招聘“最后活動”字段。 創建的評論ID也應返回。
我嘗試了這個:
BEGIN
DECLARE id INT;
INSERT INTO
`comments` (
`comments`.`recruitment_id`,
`comments`.`user_id`,
`comments`.`comment`
)
VALUES (
recruitment_id,
user_id,
com
);
SELECT
LAST_INSERTED_ID()
INTO
id;
UPDATE
`recruitments`
SET
`recruitments`.`lastActivity` = `comments`.`creationDate`
INNER JOIN
`comments`
ON
`recruitments`.`id` = `comments`.`recruitment_id`
WHERE
`comments`.`id` = id;
SELECT id;
END
但是我得到一個錯誤:
#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 'INNER JOIN `comments` ON `recruitments`.`id` = `comments`' at line 25
我敢打賭,這只是一個小錯誤,但我似乎找不到它=(
嘗試像這樣編寫主體:
BEGIN
DECLARE v_id INT;
INSERT INTO comments(recruitment_id, user_id, comment)
VALUES (v_recruitment_id, v_user_id, v_com);
SELECT v_id := LAST_INSERTED_ID();
UPDATE recruitments r INNER JOIN
comments c
ON r.id = c.recruitment_id
SET r.lastActivity = c.creationDate
WHERE c.id = v.id;
SELECT v_id;
END;
您的查詢存在幾個問題:
select
的列列表中的列名稱。 join
update
的正確語法是在update
之后放置join
邏輯。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.