-2
Student table : student ID, student name, student contact
Evaluation: EvalID, Eval number

学生从 1-7 对每节课进行评价。我需要创建一个触发器来复制学生信息,如果他们给出的评估为 7,他们给出的评估将被放入另一个表中

我所做的是

Create or replace trigger test
After Insert on evaluation
when (eval_number = 0)
Begin

我不知道从这里做什么....有什么想法吗?我的第一个触发器是否正确?

4

1 回答 1

3

下表:

CREATE TABLE student(
studentId INTEGER,
student_name varchar2(100),
student_contact varchar2(100));

CREATE TABLE evaluation(
evalId  INTEGER,
eval_num INTEGER,
student_id INTEGER)

create table eval_audit(
studentId INTEGER,
student_name VARCHAR2(100),
student_contact VARCHAR2(100),
eval_num INTEGER)

当有 7 的评估时触发插入来自学生的数据:

CREATE OR REPLACE TRIGGER AIEvaludation
AFTER INSERT ON evaluation
FOR EACH ROW
WHEN (new.eval_num = 7)
DECLARE
    CURSOR curStudent IS
        SELECT studentid, student_name, student_contact
          FROM student
         WHERE studentid = :new.student_id;
    --
    vRowStudent curStudent%ROWTYPE;
BEGIN
    OPEN curStudent;
    FETCH curStudent INTO vRowStudent;
    CLOSE curStudent;
    INSERT INTO eval_audit
    (studentid, student_name, student_contact, eval_num)
    VALUES (vRowStudent.studentid, vRowStudent.student_name, vRowStudent.student_contact, :new.eval_num);
END AIEvaludation;
于 2012-04-15T08:07:32.120 回答