2011-09-13 35 views
0

我有一个问题,使存储的MySQL函数。首先,我试图使它很容易按照官方教程:http://dev.mysql.com/doc/refman/5.0/en/create-procedure.html我的mysql函数不起作用?

create function bestalldavaror_7() 
RETURNS int DETERMINISTIC 
RETURN select sum(mangd) from bestalln where artikel_id = 7; 

的选择查询工作只是由本身和“mangd”罚款是一个int(11)值(因此是一切都在该表) 。那么,为什么这产生一个错误:

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 'select sum(mangd) from bestalln where artikel_id = 7' at line 3

+0

你可以发布你的表结构吗? – Tom

回答

1

因此使这一变化:

create function bestalldavaror_7() 
RETURNS int DETERMINISTIC 
RETURN (select sum(mangd) from bestalln where artikel_id = 7); 

,它应该工作。

+0

我试过了,它让我回来了“#1548 - 无法从mysql.proc加载,表格可能已损坏”,这很奇怪。重新表可能? – Ms01

+0

什么版本的mysql? – itsmatt

+0

什么操作系统/版本? – itsmatt