Mysql

創建過程時出錯

  • February 19, 2016

這是我的程序:

    DELIMITER $$
    CREATE PROCEDURE sp_test_final6() 
    BEGIN
   INSERT INTO `chef_ratings`(`chef_id`,`avg_total_no_votes`,`avg_total_rating`,`no_of_votes`,`avg_rating`)
   SELECT `chef_id`,(SELECT count(chef_id) FROM rates)/( SELECT count(DISTINCT chef_id) FROM rates),
   (( SELECT sum((`question_1` + `question_2` +`question_3` )/3) FROM rates ) / ( SELECT count(chef_id) FROM rates)),
   ( SELECT count(chef_id) FROM rates ),avg((`question_1`+`question_2`+`question_3`)/3)
   FROM rates GROUP BY `chef_id`;
   END $$
   DELIMITER ;

我收到錯誤:

#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 'PROCEDURE sp_test_final6()
BEGIN
INSERT INTO `chef_ratings`( `chef_id`, `avg_t' at line 1 

知道為什麼會失敗嗎?

**編輯:**它在 mysql 版本 5.5 中工作正常,但在伺服器版本:4.1.22 中它給出了這個問題。我們如何在不升級的情況下修復?

我得到了答案。MYSQL 自 5.0 起支持儲存過程。舊版本不支持儲存過程。

參考連結

引用自:https://dba.stackexchange.com/questions/65893