I made a table student, in which there is an attribute evaluation.
Now i am making a trigger in which i want that if i insert a value of zero in evaluation then a trigger should fire and store some values in audit_table.
here is my code
Create table Student ( Student_Id Number(8,2), Student_Name Varchar2(50), Gender Varchar(8), Telephone_No Number(15), Location Varchar2(200), Education Varchar2(100), Company_name Varchar2(200), No_of_attempt Number(2), Offering_Id Number(3) , EVALUATION NUMBER(2), Primary Key (Student_Id), Constraint fk_Oid Foreign Key (Offering_Id) References Course(Offering_Id) );
And now the audit table code
CREATE TABLE AUDIT_TABLE ( STUD_NAME VARCHAR2(100), COURSE_NAME
VARCHAR2(100), INSTRUCTOR_NAME VARCHAR2(200), EVALUATION NUMBER (2)
);
Now my main question is this my trigger not working
create trigger tr_student
after insert or update on student
for each row
declare
s_name student.student_name%type;
s_eval student.evaluation%type;
s_offr_id student.offering_id%type;
s_course_name student.student_name%type;
s_instr student.student_name%type;
begin
if evaluation == 0;
s_offr_id =(select offering_id from student where evaluation==0);
s_eval =0;
s_name =(select student_name from student where evaluation==0);
s_course_name =(select course_name from course where offering_id==s_offr_id);
s_instr=(select name from instructor where offering_id==s_offr_id);
insert into AUDIT_TABLE values(s_name,s_course,s_instr,s_eval);
end;
Is there some problem with my trigger?
This is not possible:
Change it to
Note there are two problems. First, you need
intoto select a value into a variable. Second, the comparison operator in SQL is only a single=.The same goes for
It should be
So there, the you forgot the
thenandend if, the comparison operator is wrong and you need:new.fieldnameto get the value of the field, instead of a local variable.The assignment operator in PLSQL is
:=, soshould be changed to
It seems you need to grab the schoolbook again and do some more reading. 🙂