mysql 是否对存储过程中的 sql 强制执行特殊语法约束? (选择问题)
我经常很难在 mysql 中创建存储过程。语法应该很好,只是不在存储过程中进行解析。这是一个仍然没有被解析的简化版本。我无法将此代码转换为可以解析的内容。
update..set 子句出现问题
UPDATE
我进一步简化了代码。问题仍然存在。错误消息似乎很隆隆
更新 2
解决了,感谢 Mark Byers。 select
语句中的 into
子句必须仔细定位。请注意 mysql 错误消息是多么具有误导性和糟糕性!
错误 1064 (42000):您的 SQL 语法有错误;检查手册
更新页面 放 左翼 = 1 其中 lft > 3 AN' 在第 22 行
代码:
CREATE PROCEDURE `move_page_right`( subject_id SMALLINT UNSIGNED, reference_id SMALLINT UNSIGNED)
BEGIN
select
p.lft,
p.rgt,
p.rgt - p.lft,
p.rgt + 1
into
@subject_old_lft,
@subject_old_rgt,
@subject_width,
@subject_old_right_sibling_lft
from page p
where p.page_id = subject_id;
select p.rgt + 1
from page p
into @subject_new_lft
where p.page_id = reference_id;
UPDATE page
SET
lft = 1
where lft > 3 AND lft < 3;
END
I am often having a very hard time to create a stored procedure in mysql. Syntax which should really be fine just get not parsed within a stored procedure. Here is a simplified version that still doesn't get parsed. I am not able to turn this code into something that can be parsed.
The update..set clause gives problems
UPDATE
I've simpiflied the code even more. Problem still exists. Error messages seems to be rumble
UPDATE 2
Solved, thanks to Mark Byers. The into
clause in a select
-statement must be positioned carefully. Note how misleading and bad the mysql error mesage is!
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual
UPDATE page SET lft = 1 where lft > 3 AN' at line 22
The code:
CREATE PROCEDURE `move_page_right`( subject_id SMALLINT UNSIGNED, reference_id SMALLINT UNSIGNED)
BEGIN
select
p.lft,
p.rgt,
p.rgt - p.lft,
p.rgt + 1
into
@subject_old_lft,
@subject_old_rgt,
@subject_width,
@subject_old_right_sibling_lft
from page p
where p.page_id = subject_id;
select p.rgt + 1
from page p
into @subject_new_lft
where p.page_id = reference_id;
UPDATE page
SET
lft = 1
where lft > 3 AND lft < 3;
END
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
抱歉,我只是在这里猜测,但希望我很快就能得到它......来自 SELECT 文档:
我强烈怀疑这些子句的顺序很重要。在您的查询中,您混淆了顺序,我认为这可能会带来问题,尽管错误消息具有误导性。
WHERE 子句应该在 INTO 之前:
这里 INTO 和 FROM 也颠倒了:
尝试改变它,看看是否有帮助。
Sorry, again I'm just guessing here, but hopefully I'll get it soon... from the documentation for SELECT:
I would strongly suspect that the order of these clauses is important. In your queries you mix up the order, and I think this might be giving the problems, although the error messages are misleading.
The WHERE clause should be before the INTO here:
and here the INTO and FROM are also reversed:
Try changing it round and see if it helps.
我不认为表别名出现在 UPDATE 部分中。尝试删除别名。如果您的 UPDATE 语句引用多个表,那么您可以将更新的表放在 FROM 子句(或任何联接)中,并仅在 UPDATE 部分中使用别名。
我不了解 MySQL,但这就是它在 MS SQL 中的工作方式,所以它可能是 ANSI 标准。
我也不确定你想实现什么目标。您将列设置为自身,这不会执行任何操作。
I don't think that the table alias goes in the UPDATE portion. Try just removing the alias. If your UPDATE statement references multiple tables then you can put the updated table in the FROM clause (or any join) and use ONLY the alias in the UPDATE portion.
I don't know about MySQL, but that's how it works in MS SQL, so it may be ANSI standard.
I'm also not sure what you're trying to accomplish. You're setting the columns to themselves, which isn't going to do anything.