Professional Documents
Culture Documents
>>INSERTION OF VALUES
>STUDENT
begin
insert into student values(:rollno,:name,2);
end;
>Violation in inserting rollno.
create or replace trigger firsttrig before insert or update on student for each
row
when (new.rollno<1001)
begin
raise_application_error (-20001,'invalid rollno');
end;
>BOOK
declare
bookno number;
bname varchar(25);
noc number;
noc1 number;
author varchar(15);
publication varchar(10);
nobooks number;
lib_rec lib%rowtype;
begin
bookno:= :bookno;
bname:= :bookname;
author:= :author;
publication:= :publication;
noc:= :noofcopies;
noc1:= noc;
select count(*) into nobooks from lib where bookname=bname;
if nobooks=0 then
insert into lib values(bname,author,publication,noc);
else
update lib set noofcopies=noofcopies+noc where bookname=bname;
end if;
while noc!=0
loop
insert into books values(bookno,bname,'yes',0);
noc:=noc-1;
bookno:=bookno+1;
end loop;
end;
>>DISPLAYING DATABASE
select * from lib;
select * from books;
select * from student;
dbms_output.put_line('***************');
else
select min(bookno) into book_no from books where bookname=bname and available='y
es';
insert into subscription values(book_no,roll_no,sysdate,sysdate+7,0,'ntreturned'
);
update student set no_card=no_card-1 where rollno=roll_no;
update books set available='no' where bookno=book_no;
update books set subscribed_to=roll_no where bookno=book_no;
end if;
end if;
exception
when no_data_found then
dbms_output.put_line('***************');
dbms_output.put_line('u are not a user');
dbms_output.put_line('***************');
end;
>> SUBSCRIBE
declare
begin
sub('bookname',rollno);
end;
select * from books;
select * from subscription;
select * from student;
dbms_output.put_line('$$$$$$$$$$$$');
end if;
update subscription set status='returned' where bookno=bno;
update student set no_card=no_card+1 where rollno=book_rec.subscribed_to;
update books set available='yes' where bookno=bno;
update books set subscribed_to=0 where bookno=bno;
end if;
exception
when no_data_found then
dbms_output.put_line('$$$$$$$$$$$$');
dbms_output.put_line('book doesnot belong to library');
dbms_output.put_line('$$$$$$$$$$$$');
end;
>>RETURN
declare
begin
ret (bookno);
end;
select * from subscription;
select * from books;
select * from student;
>>UPDATION OF PARTICULARS OF STUDENT
CREATE OR REPLACE TRIGGER studentUPDATE
AFTER UPDATE OF NAME ON student FOR EACH ROW
BEGIN
DBMS_OUTPUT.PUT_LINE('OLD NAME: ' ||:OLD.NAME);
DBMS_OUTPUT.PUT_LINE('NEW NAME:' ||:NEW.NAME);
END;
-- update student set name = 'vijay' where rollno = 1009;
CREATE OR REPLACE TRIGGER
AFTER UPDATE OF ROLLNO ON
BEGIN
DBMS_OUTPUT.PUT_LINE('OLD
DBMS_OUTPUT.PUT_LINE('NEW
END;
studentUPDATE2
student FOR EACH ROW
ROLLNO: ' ||:OLD.ROLLNO);
ROLLNO:' ||:NEW.ROLLNO);