无法创建存储函数 - 语法错误?
我有以下问题。
我想创建一个存储函数,将实体 ID 转换为相应的 sku
这是代码:
CREATE FUNCTION `id2sku`(`entity_id_in` INT)
RETURNS VARCHAR
LANGUAGE SQL
NOT DETERMINISTIC
CONTAINS SQL
SQL SECURITY DEFINER
COMMENT ''
BEGIN
DECLARE returnvalue varchar(50);
SELECT `sku` INTO returnvalue FROM catalog_product_entity WHERE entity_id = entity_id_in LIMIT 1;
return returnvalue;
END
现在我的问题是,如果我触发查询,我会收到以下消息: [窗口标题] 错误
SQL 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 'LANGUAGE SQL
NOT DETERMINISTIC
CONTAINS SQL
SQL SECURITY DEFINER
COMMENT' at line 3
我使用的数据库是 MySQL 5.0.51a
提前感谢您的想法。
I've got the following Problem.
I want to create a stored function which converts an entity_id into the corresponding sku
Here's the code:
CREATE FUNCTION `id2sku`(`entity_id_in` INT)
RETURNS VARCHAR
LANGUAGE SQL
NOT DETERMINISTIC
CONTAINS SQL
SQL SECURITY DEFINER
COMMENT ''
BEGIN
DECLARE returnvalue varchar(50);
SELECT `sku` INTO returnvalue FROM catalog_product_entity WHERE entity_id = entity_id_in LIMIT 1;
return returnvalue;
END
Now my problem is if i fire the query i get the following message:
[Window Title]
Error
SQL 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 'LANGUAGE SQL
NOT DETERMINISTIC
CONTAINS SQL
SQL SECURITY DEFINER
COMMENT' at line 3
The db im using is MySQL 5.0.51a
Thanks in advance for your ideas.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
MySQL 默认使用
;
作为分隔符,因此当它在第 9 行遇到;
时:MySQL 认为命令结束 - 它正在尝试执行:
这是无效的SQL。
设置新的分隔符:
然后您可以使用以下命令将分隔符更改回来:
MySQL by default uses
;
as a delimiter, so when it encounters the;
at line 9:MySQL thinks the command ends - it is trying to execute:
which isn't valid SQL.
Set a new delimiter:
You can then change the delimiter back with:
这应该有效:
您没有指定 varchar 长度。 :-)
This should work:
You had not specified the varchar length. :-)