Você está na página 1de 3

1) Procedure to update backup student table based on the actual student table wi

th
IMPLICIT CURSOR
CREATE or REPLACE procedure updateemail_du(ssnidc IN integer)
IS
rowcount integer := 0;
BEGIN
update dummystudent set emailid= (select emailid from student where ssnid= ssnid
c) where ssnid = ssnidc;
IF sql%NOTFOUND THEN
DBMS_OUTPUT.PUT_LINE('Nothing Updated');
ELSE IF SQL%FOUND THEN
rowcount := sql%rowcount;
DBMS_OUTPUT.PUT_LINE('Row count'|| 'email ids updated');
END IF;
END;
/
2) Procedure to increase the scholarship amount of a student with demonstration
of IN OUT parameter and EXPLICIT CURSOR
CREATE or REPLACE procedure increasescholarship
(ssnid_f IN stud_sch.ssnid_fk%TYPE, increase_sch INOUT scholarship.scholarshipam
ount%TYPE)
IS
tempincrease number;
BEGIN
select scholarshipamount into tempincrease from scholarship s, stud_sch sch wher
e s.scholarshipid = sch.scholarshipid_fk and
sh.ssnid = ssnid_f;
IF tempincrease BETWEEN 20000 and 30000 THEN
increasescholarship := tempincrease * 2.2;
ELSE IF tempincrease BETWEEN 30000 and 40000 THEN
increasescholarship := tempincrease * 3.2;
ELSE IF tempincrease BETWEEN 40000 and 50000 THEN
increasescholarship := tempincrease * 4.2;
ELSE IF tempincrease > 50000
increasescholarship := tempincrease * 5.2;
END IF;
END;
/
DECLARE
CURSOR update_sch IS
select sh.ssnid.s.scholarshipamount from scholarship s, stud_sch sh where
sh.scholarship_fk = s.scholarshipid;
pre_schamt number;
BEGIN
FOR schrecord IN update_sch LOOP
pre_schamt := schrecord.scholarshipamount;

increasescholarship(schrecord.ssnid,schrecord.scholarshipamount)
DBMS_OUTPUT.PUT_LINE('The scolarship amount of'||schrecord.ssnid||'increased fro
m'||pre_schamt||'to'||schrecord.scholarshipamount);
END LOOP;
END;
/
3) TRIGGER to log the count of rows after deletion has been performed.(STATEMENT
LEVEL TRIGGER)
CREATE or REPLACE trigger log_trig
after delete on student
DECLARE
vt pls_integer := 0;
BEGIN
select count(*) into vt from student;
insert into recordcount values(user,sysdate,vt);
end;
/

4) TRIGGER to log the count of rows after deletion has been performed.(ROW LEVEL
TRIGGER)
CREATE or REPLACE trigger log_trig1
before delete on student
for each row
BEGIN
insert into recordcount1 values
(:old.ssnid,:old.firstname,sysdate,user);
end;
/
5) FUNCTION WITHIN A PROCEDURE OR CODE BLOCK.
A PROCEDURE to calculate total flight amount with taxes.
CREATE OR REPLACE procedure calc_studflig_pay(ssnid IN number) AS
stu_rec journeydetail%ROWTYPE;
pay_total number;
-- function for state tax
FUNCTION calc_state(sal IN number)
RETURN number IS
BEGIN
RETURN sal * 0.8;
END;
-- function for fedaral tax
FUNCTION calc_federal(sal IN number)
RETURN number IS
BEGIN
RETURN sal * 0.12;
END;

BEGIN
DBMS_OUTPUT.PUT_LINE('Calculating pay with taxes');
select * INTO stu_rec from journeydetails where ssnid_fk = ssnid;
pay_total := stu_rec.amountpaid + calc_state(stu_rec.amountpaid) + calc_federal(
stu_rec.amountpaid);
DBMS_OUTPUT.PUT_LINE('The total payment for'||stu_rec.ssnid_fk||'is'||pay_total)
;
EXCEPTION
WHEN NO_DATA_FOUND THEN
RAISE_APPLICATION_ERROR(-20001,'No matching student for the given ID');
END;

Você também pode gostar