2010-09-30 221 views
0

我通過phpMyAdmin的 http://www.databasejournal.com/features/mysql/article.php/3569846/MySQL-Stored-Functions.htm創建功能 - 錯誤1064

mysql> DELIMITER | 
mysql> 
CREATE FUNCTION WEIGHTED_AVERAGE (n1 INT, n2 INT, n3 INT, n4 INT) 
    RETURNS INT 
    DETERMINISTIC 
    BEGIN 
    DECLARE avg INT; 
    SET avg = (n1+n2+n3*2+n4*4)/8; 
    RETURN avg; 
    END| 

試過了這個例子這工作

DELIMITER | 

下一個語句了:

Error 

SQL query: 

CREATE FUNCTION WEIGHTED_AVERAGE(
n1 INT, 
n2 INT, 
n3 INT, 
n4 INT 
) RETURNS INT DETERMINISTIC BEGIN DECLARE avg INT; 

MySQL said: Documentation 
#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 '' at line 5 
+1

您使用的是哪個MySQL版本?我會說這是phpAdmin的錯誤,因爲這是從命令行客戶端 – nos 2010-09-30 13:45:05

+0

hi nos - 你的解決方案工作 - 它從命令行罰款。想添加一個答案? – siliconpi 2010-09-30 14:19:27

回答

0

因爲它在鏈接中提到:

As mentioned in the first stored procedures tutorial, we declare the "|" symbol as a delimiter, so that our function body can use ordinary ";" characters 

你可以寫很多不同的連續行的命令。但通常只有當';',洞聲明被執行。
設置一個DELIMITER字符意味着MySQL應該等到這個關閉,無論您使用'; ''',然後才解釋分隔符之間的內容。