Solution:
1) Write a trigger before insert or update on No_of_shares field should not be zero. (Raise user defined exception and give appropriate message)
SQL> set serveroutput on
SQL> create or replace trigger t3 before insert or update on com_per
for each row
begin
if(:new.no_of_shares<=0)then
raise_application_error(-20001,'no_of_shares> O');
end if;
end;
/
Trigger created.
2) Write a function to display total no_of_shares of a specific person.
SQL> set serveroutput on SOL> create or replace function f2(xyz in varchar) return number as abc number;
begin
select sum(person3.pno) into abc from company0 person3,com_per where companyo.cid=com_per.cid and person3.pno=com_per.pno and pname='ppp';
if sql %found then
return(abc);
else
return null;
end if;
end f2;
/
Function created.
SQL> begin
dbms_output.put_line('company'||f2('ppp'));
end;
/
0 Comments