2014-03-01 48 views
0

我正在做一個家庭作業,它需要基於標記的字母等級更新。兩者都必須通過程序完成。第一個使用隱式遊標,第二個使用顯式遊標。我明確的遊標過程完美地工作。然而,我的隱式遊標有兩個問題。第一,它似乎沒有更新爲50的標記。第二,顯示輸出時顯示學生ID,但不是更新的成績。任何想法來解決這些問題?以下是我迄今爲止:隱式光標循環中帶有DBMS輸出的PL/SQL過程

CREATE OR REPLACE PROCEDURE comp_grade_s IS 
    CURSOR cur_class IS 
    SELECT studid, marks, grade 
    FROM class 
    FOR UPDATE NOWAIT; 
    TYPE type_class IS RECORD 
    (studid class.studid%TYPE, 
    marks class.marks%TYPE, 
    grade class.marks%TYPE); 
    rec_class type_class; 
    lv_grade_txt class.grade%TYPE; 
BEGIN 
    OPEN cur_class; 
    LOOP 
    FETCH cur_class INTO rec_class; 
     EXIT WHEN cur_class%NOTFOUND; 
     UPDATE class 
     SET grade = 'F' 
     WHERE marks < 50; 
     UPDATE class 
     SET grade = 'D' 
     WHERE marks >= 50 AND marks < 60; 
     UPDATE class 
     SET grade = 'C' 
     WHERE marks >= 60 AND marks < 70; 
     UPDATE class 
     SET grade = 'B' 
     WHERE marks >= 70 AND marks < 80; 
     UPDATE class 
     SET grade = 'A' 
     WHERE marks >= 80; 
     UPDATE class 
     SET grade = lv_grade_txt 
     WHERE CURRENT OF cur_class; 
     DBMS_OUTPUT.PUT_LINE('Student ID: ' || rec_class.studid || ' gets grade ' || 
     lv_grade_txt); 
    END LOOP; 
    CLOSE cur_class; 
END; 

預先感謝任何幫助, 艾米麗

回答

0

試試這個,我不知道爲什麼ü沒有要打印的等級從該DBMS_OUTPUT

已在其中定義

創建或替換PROCEDURE comp_grade_s

記錄是

CURSOR cur_class爲

SELECT studid, marks, grade 

FROM class 

FOR UPDATE NOWAIT;

TYPE type_class IS RECORD

(studid class.studid%TYPE, 

marks class.marks%TYPE, 

grade class.grade%TYPE); 

rec_class type_class;

BEGIN

OPEN cur_class;

LOOP

FETCH cur_class INTO rec_class; 

    EXIT WHEN cur_class%NOTFOUND; 

    UPDATE class 

    SET grade = 'F' 

    WHERE marks < 50; 

    UPDATE class 

    SET grade = 'D' 

    WHERE marks >= 50 AND marks < 60; 

    UPDATE class 

    SET grade = 'C' 

    WHERE marks >= 60 AND marks < 70; 

    UPDATE class 

    SET grade = 'B' 

    WHERE marks >= 70 AND marks < 80; 

    UPDATE class 

    SET grade = 'A' 

    WHERE marks >= 80; 

    UPDATE class 

    SET grade = lv_grade_txt 

    WHERE CURRENT OF cur_class; 

    DBMS_OUTPUT.PUT_LINE('Student ID: ' || rec_class.studid || ' gets grade ' || 

    rec_class.grade); 

END LOOP;

CLOSE cur_class;

END;