-1

以下は私のMySQLの手順です。

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;' 

早くもこれを完了する必要がありますが、何が悪かったのか理解できないようです。前もって感謝します。

4

1 に答える 1

1

この行を確認してください:

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

6つの開き括弧と7つの閉じ括弧があるため、構文エラーが発生します。

最後に閉じたものは必要ないようですので削除してください

SET gpa = ((round( abs( (rand( ) *100 ) )) %5)*2)+2.12;
于 2013-01-23T12:27:20.323 に答える