PLSQL
PLSQL
declare
srec sailors%rowtype;
cursor c1 is select * from sailors;
begin
open c1;
fetch c1 into srec;
while c1%found
loop
if srec.age>=40 then
update sailors set salary=salary+500 where sid=srec.sid;
elsif srec.age>=30 and srec.age<40 then
update sailors set salary=salary+300 where sid=srec.sid;
else
update sailors set salary=salary+100 where sid=srec.sid;
end if;
fetch c1 into srec;
end loop;
close c1;
end;
Mytrig2.sql
CREATE OR REPLACE TRIGGER Print_salary_changes
BEFORE DELETE OR INSERT OR UPDATE ON sailors
FOR EACH ROW
DECLARE
sal_diff number;
BEGIN
sal_diff := :NEW.SALARY - :OLD.SALARY;
dbms_output.put('Old salary: ' || :OLD.salary);
dbms_output.put(' New salary: ' || :NEW.salary);
dbms_output.put_line(' Difference ' || sal_diff);
END;
/