Zeba Functions2
-
Upload
nagarajuvcc123 -
Category
Documents
-
view
215 -
download
0
description
Transcript of Zeba Functions2
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.
CREATE OR REPLACE FUNCTION STUDEL(p_admno number) RETURN NUMBER ISBEGIN DELETE FROM STU
WHERE ADMNO=P_ADMNO; COMMIT;
RETURN 1;END;Write plsql program to send the parameter as student details and insert into stu table.
CREATE OR REPLACE FUNCTION STUINSERT(p_admno number, p_sname varchar2, p_course varchar2, p_fee number) return number isBEGIN INSERT INTO STU
VALUES(p_admno,p_sname,p_course,p_fee); COMMIT; RETURN 1;END;
Write plsql program to send the parameter as student admno and fee and fee decreased from the stu table.
CREATE OR REPLACE FUNCTION STUFEEPAY(P_ADMNO NUMBER, P_FEE NUMBER) RETURN NUMBER IS
BEGIN UPDATE STU
SET FEE=FEE-P_FEE
WHERE ADMNO=P_ADMNO; COMMIT; RETURN 1;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.