You are on page 1of 2

Calling function from another functions: Master and Child functions coding.

Here first function receive some


parameter(arguments) and those send to another function2 after getting the results of function2 processed within
the function1 and return the value to the subprogram.
create or replace function fun1(a number, b number) return number is
big number;
begin
if a>b then
big:=a;
else
big:=b;
end if;
return big;
end;
create or replace function fun2 (a number, b number, c number) return number is
x number;
y number;
begin
x:= fun1 (a,b);
y:=c*x;
return y;
end fun2;
Functions to DML operations for a table: By using function we can operate dml operations with in the
database like insertion, deletion and updating.
Example:
Write plsql program to send the parameter as admission and delete it from the stu table.

CREATEORREPLACEFUNCTIONSTUDEL(p_admnonumber)RETURNNUMBERIS
BEGIN
DELETEFROMSTU
WHEREADMNO=P_ADMNO;
COMMIT;
RETURN1;
END;
Write plsql program to send the parameter as student details and insert into stu table.

CREATEORREPLACEFUNCTIONSTUINSERT(p_admnonumber,p_snamevarchar2,
p_coursevarchar2,p_feenumber)returnnumberis
BEGIN
INSERTINTOSTU
VALUES(p_admno,p_sname,p_course,p_fee);
COMMIT;
RETURN1;
END;
Write plsql program to send the parameter as student admno and fee and fee decreased from the stu table.

CREATEORREPLACEFUNCTIONSTUFEEPAY(P_ADMNONUMBER,P_FEENUMBER)RETURN
NUMBERIS
BEGIN
UPDATESTU
SETFEE=FEEP_FEE
WHEREADMNO=P_ADMNO;
COMMIT;
RETURN1;
END;

DECLARE
N NUMBER;
BEGIN
N:=STUINSERT(20,'Zeba','Oracle',500);
END;

DECLARE
N NUMBER;
BEGIN
N:=STUDEL(14);
END;
DECLARE
N NUMBER;
BEGIN
N:=STUFEEPAY(13,500);
END;
Practice the above similar coding for Books table.

You might also like