Professional Documents
Culture Documents
Program 6 Trigger
Program 6 Trigger
: 6
Date :
TRIGGER
AIM:
ALGORITHM:
Step 2: Create a trigger and trigger name and when the trigger is execute is given.
Step 3: Declare a cursor and fetch the cursor student table record into the cursor variable.
Step 4: Create a variable and data types to store the updated values.
Step 6: Update the table using update query,we use the loop here so all record are updated.
QUERY:
Table Created
SQL>DESC STUDENT
NAME VARCHAR2(25)
SUB1 NUMBER(2)
SUB2 NUMBER(2)
SUB3 NUMBER(2)
SUB4 NUMBER(2)
SUB5 NUMBER(2)
TOTAL. NUMBER(3)
RESULT. VARCHAR2(10)
SQL>Create or replace trigger student
declare
x student%rowtype;
tot student.total%type;
res student.result%type;
begin
for x in c
loop
if(x.sub1>=50)and(x.sub2>=50)and(x.sub3>=50)and(x.sub4>=50)and(x.sub5>=50)then
res:=’PASS’;
else
res:=’FAIL’;
end if;
dbms_output.put_line(‘Roll No:’||x.rno);
dbms_output.put_line(‘Name:’||x.name);
dbms_output.put_line(‘Total:’||tot);
dbms_output.put_line(‘Result’||res);
end loop;
dbms_output.put_line(‘RECORD UPDATED’);
Exception
When no_data_found then
End studriger;
Trigger created.
SQL>set serveroutput on
Values(‘&rno’,’ &name’,&sub1,&sub2,&sub3,&sub4,&sub5)
New 2:values(‘MCA003’,’MOHAN’,80,70,80,90,60)
Roll No:MCA001
Name:HARI
Total:410
Result:FAIL
Roll No:MCA002
Name:MAHESH
Total:420
Result:FAIL
RECORD UPDATED
1 row created.
SQL>SELECT * FROM STUDENT;
Result:-