2013-01-23 121 views
-1

以下是我的MySQL過程。MySQL過程中的錯誤:錯誤1064

DELIMITER $$ 

DROP PROCEDURE IF EXISTS set_dummy_feedback $$ 
CREATE PROCEDURE set_dummy_feedback () 
BEGIN 
-- First we declare all the variables we will need 
DECLARE current_code,current_emp_id,current_subject_id  VARCHAR(150); 
DECLARE current_count_facultyfeedback,current_count_studentfeedback  INT  DEFAULT 0; 
DECLARE temp_index              INT  DEFAULT 0; 
DECLARE gpa                DECIMAL(4,2); 
-- flag which will be set to true, when cursor reaches end of table 
DECLARE exit_loop BOOLEAN;   

-- Declare the sql for the cursor 
DECLARE example_cursor CURSOR FOR 
SELECT DISTINCT emp_id,subject_id,code,c 
FROM feedback_subjectfaculty 

ORDER BY `c` ASC ; 
-- Let mysql set exit_loop to true, if there are no more rows to iterate 
DECLARE CONTINUE HANDLER FOR NOT FOUND SET exit_loop = TRUE; 

-- open the cursor 
OPEN example_cursor; 

-- marks the beginning of the loop 
example_loop: LOOP 

-- read the name from next row into the variable l_name 
FETCH example_cursor INTO current_emp_id,current_subject_id,current_code,current_count_facultyfeedback; 

-- check if the exit_loop flag has been set by mysql, 
-- if it has been set we close the cursor and exit 
-- the loop 
IF exit_loop THEN 
    CLOSE example_cursor; 
    LEAVE example_loop; 
END IF; 
-- fetch data from table feedback_studentfeedback 
SELECT SQL_CALC_FOUND_ROWS * FROM `feedback_studentfeedback` where 
fb_subjects_10 like CONCAT("%",current_code,"%") ; 
-- save the number of rows fetched in the previous select 
SET current_count_studentfeedback = FOUND_ROWS() ; 
SET temp_index = current_count_studentfeedback ; 
IF temp_index IS NULL 
    THEN SET temp_index = 0; 
END IF; 
IF current_count_facultyfeedback IS NULL 
    THEN SET current_count_facultyfeedback = 0; 
END IF; 

WHILE temp_index > current_count_facultyfeedback DO 

    SET gpa = ((round(abs((rand() *100))) %5)*2)+2.12); 
    IF gpa > 10.0 
     THEN SET gpa = 8.12; 
    END IF; 

    INSERT INTO tbl2 VALUES    
    ('B.Tech', 
    'CSE', 
    current_emp_id, 
    '0', 
    current_subject_id, 
    'MONSOON', 
    "2012", 
    (round(abs((rand() *100))) %5 +1), 
    '', 
    gpa); 
SET temp_index = temp_index - 1; 
END WHILE; 
END LOOP; 
CLOSE example_cursor; 

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 

    '); 
    IF gpa > 10.0 
     THEN SET gpa = 8.12; 
    END IF;' 

我需要儘早完成這一點,但似乎無法找出什麼地方出了錯。 在此先感謝。

回答

1

檢查這一行:

SET gpa = ((round(abs((rand() *100))) %5)*2)+2.12); 

你有6個左括號和7關閉的,導致語法錯誤

刪除最後一個關閉一個,因爲它似乎並沒有被要求

SET gpa = ((round(abs((rand() *100))) %5)*2)+2.12; 
+0

那是太愚蠢。非常感謝。 –