-2
SQL查詢:MySQL的Prosedural語言1個
CREATE PROCEDURE tree_add_node(IN id int(11), IN name varchar(50), IN label varchar(50))
BEGIN
DECLARE lft_value int(11), rht_value int(11), lvl_value int(11);
START TRANSACTION;
SELECT `lft` INTO lft_value FROM trees WHERE `tree_id`=id;
SELECT `rht` INTO rht_value FROM trees WHERE `tree_id`=id;
SELECT `lvl` INTO lvl_value FROM trees WHERE `tree_id`=id;
UPDATE `trees` SET `tree_id`=`tree_id` +1,`description`='null',`lft`=`lft`+2,`rht`=`rht`+2 WHERE `tree_id`>= id;
INSERT INTO `trees`(`tree_id`, `name`, `label`, `description`, `lft`, `rht`, `lvl`) VALUES (id,'name','label',NULL,lft_value,rht_value,lvl_value)
COMMIT;
END;
MySQL表示:
#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 ' rht_value int(11), lvl_value int(11); START TRANSACTION; SELECT
`lft` INTO lf' at line 3
外觀正常。這是一個語法錯誤。並且簡單地複製粘貼代碼而沒有解釋任何東西都不會幫助你。 –
如果我能找到我的錯誤,那麼我不會發布它 –
http://dev.mysql.com/doc/refman/5.7/en/declare-local-variable.html – Shadow