0
我有這個功能。這是不完整的,沒有做任何有意義的是,但在寫作過程中我已經收到此錯誤:FOR LOOP的語法錯誤
ERROR: syntax error at or near "LOOP"
LINE 26: END LOOP;
任何人都可以看我的代碼,看看爲什麼?我for循環語法對我來說看起來很好。
CREATE FUNCTION assignGrades(prob numeric[], school_name text, school_id bigint) RETURNS void AS $$
DECLARE
num_grades integer ARRAY[6];
found_school school_probs%ROWTYPE;
num_students simulated_records%ROWTYPE;
num_students_int bigint;
random_record simulated_records%ROWTYPE;
BEGIN
SELECT INTO found_school * FROM school_probs WHERE school_code = school_id;--select the prob dist
SELECT INTO num_students * FROM simulated_records WHERE school = school_name;
SELECT COUNT(*) INTO num_students_int FROM simulated_records WHERE school = school_name;
num_grades[1] = num_students_int*found_school.probs[1];
num_grades[2] = num_students_int*found_school.probs[1];
num_grades[3] = num_students_int*found_school.probs[1];
num_grades[4] = num_students_int*found_school.probs[1];
num_grades[5] = num_students_int*found_school.probs[1];
num_grades[6] = num_students_int*found_school.probs[1];
FOR i IN 1..num_grades[1] LOOP
SELECT INTO random_record * FROM simulated_records WHERE school = school_name ORDER BY RANDOM() LIMIT 1;
IF random_record.grade IS NULL THEN
random_record.grade = 'A';
END LOOP;--syntax error here
END;
$$
LANGUAGE plpgsql