Solution:
1) Write a procedure which will accept teacher name frm user and display his/her college details.
SQL> set serveroutput on
SQL> create or replace procedure p1(n in varchar) as cursor c1 is select tname, cname from college20.tid=teacher2.tid and tname ='aaa';
c c1%rowtype;
begin
open c1;
dbms_output.put_line('tname'|| " || 'cname');
loop
fetch c1 into c;
exit when c1%notfound;
if(c.tname=n)then
dbms_output.put_line(c.tname || " || c.cname);
end if;
end loop;
close c1;
end;
/
Procedure created.
SQL> begin
p1 ('aaa')
end;
/
2) Write a trigger which will fire before insert or update on Teacher having salary less than or equal to zero(Raise user defined exception and give appropriate message)
SQL> set serveroutput on;
SQL> create or replace trigger t4 before insert or update on teacher2
for each row
begin
if(:new.salary<=0)then
raise_application_error(-20001,'salary>0');
end if;
end;
/
Trigger created.
0 Comments