0% found this document useful (0 votes)
30 views11 pages

Question1,2,3 Ass5

Uploaded by

wacih58121
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views11 pages

Question1,2,3 Ass5

Uploaded by

wacih58121
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 11

1.

Write a PL/SQL stored Procedure for following requirements and call the procedure in

appropriate PL/SQL block.

1. Borrower(Rollin, Name, DateofIssue, NameofBook, Status)

2. Fine(Roll_no,Date,Amt)

 Accept roll_no &name of book from user.

 Check the number of days (from date of issue), if days are between 15 to 30 then fine

amount will be Rs 5per day.

 If no. of days>30, per day fine will be Rs 50 per day & for days less than 30, Rs. 5 per

day.

 After submitting the book, status will change from I to R.

 If condition of fine is true, then details will be stored into fine table.

create or replace procedure assign5_proc(mroll IN number)

is

mdate date;

mfine number(10);

datediff number(10);

begin

select dateofissue into mdate from sci_borrower26 where

roll_no=mroll;

datediff:=to_date(sysdate)-to_date(mdate);
if(datediff<15) then

dbms_output.put_line('No Fine');

update sci_borrower26 set status='R'where

roll_no=mroll;

elsif(datediff >15 and datediff <30) then

mfine:=(datediff*5);

dbms_output.put_line('Fine is '||mfine);

update sci_borrower26 set status='R' where roll_no=mroll;

insert into sci_fiine26 values(mroll,sysdate,mfine);

elsif(datediff>30) then

mfine:=((datediff-30)*50+(30*5));

dbms_output.put_line('Fine is'||mfine);

update sci_borrower26 set status='R' where roll_no=mroll;

insert into sci_fiine26 values(mroll,sysdate,mfine);

end if;

commit;

end;

declare
mroll number;

mbook varchar(20);

begin

mroll:=&mroll;

assign5_proc(mroll);

end;

output

SQL> show errors

No errors.

SQL> declare

2 mroll number;

3 mbook varchar(20);

4 begin

5 mroll:=&mroll;

6 assign5_proc(mroll);

8 end;

9 /

Enter value for mroll: 21

old 5: mroll:=&mroll;

new 5: mroll:=21;
PL/SQL procedure successfully completed.

SQL> 25

SP2-0226: Invalid line number

SQL> /

Enter value for mroll: 25

old 5: mroll:=&mroll;

new 5: mroll:=25;

PL/SQL procedure successfully completed.

SQL> /

Enter value for mroll: 26

old 5: mroll:=&mroll;

new 5: mroll:=26;

PL/SQL procedure successfully completed.

SQL> select*from sci_borrower26;

ROLL_NO DATEOFISS NAMEOFBOOK STATU

---------- --------- ---------- -----

25 27-APR-24 dune R

26 27-JAN-23 amednagar R
21 20-MAR-22 mumbai R

11 19-APR-20 pune

2. Write a stored function in PL/SQL for given requirement and use the same in PL/SQL block.

Account no. and branch name will be accepted from user. The same will be searched in table

acct_details. If status of account is active then display appropriate message and also store the

account details in active_acc_details table, otherwise display message on screen “account is

inactive”.

create or replace function sort_active_acc(macc in number)

return number

is

mbranch number(15);

mstat char;

begin

select branch_no, status into mbranch, mstat from acc_26 where acc_no = macc;

if mstat = 'A' then

insert into active_acc_26 values (macc, mbranch);

return 1;

else

return 0;

end if;

end;

declare
macc number;

res number;

begin

macc := &macc;

select acc_no into macc from acc_26 where acc_no = macc;

res := sort_active_acc(macc);

if res = 1 then

dbms_output.put_line('Account is active!');

else

dbms_output.put_line('Account is inactive!');

end if;

exception

when no_data_found then

dbms_output.put_line('Account does not exist!');

end;

output

Enter value for macc: 2222222222

old 5: macc := &macc;

new 5: macc := 2222222222;

Account is active!

PL/SQL procedure successfully completed.

select*from active_acc_26;
ACC_NO BRANC_no

---------- ---------------

1111111111 56

2222222222 63

3. Write a Stored Procedure namely proc_Grade for the categorization of student. If marks
scored

by students in examination is <=1500 and marks>=990 then student will be placed in

distinction category if marks scored are between 989 and900 category is first class, if
marks

899 and 825 category is Higher Second Class

Write a PL/SQL block for using procedure created with above requirement.

Stud_Marks(name, total_marks)

Result(Roll,Name, Class)

SQL> select*from stu_26;

NAME MARKS

---------- ----------

yash 96

hrutvik 65

pranv 85

create or replace procedure proc_Grade(mroll in number, mname in varchar)

is

mtotal_marks number;
Begin

select total_marks into mtotal_marks from Stu_26 where roll=mroll;

if mtotal_marks&lt;=1500 and mtotal_marks&gt;=990 then

insert into result_26 values(mroll, mname, &#39;Distinction&#39;);

elsif mtotal_marks&lt;=989 and mtotal_marks&gt;=900 then

insert into result_26 values(mroll, mname, &#39;First Class&#39;);

elsif mtotal_marks&lt;=899 and mtotal_marks&gt;=825 then

insert into result_26 values(mroll, mname, &#39;Higher Second Class&#39;);

else

insert into result_26 values(mroll, mname, &#39;Fail&#39;);

end if;

End;

Declare

roll number;

name varchar(20);

Begin

roll:=&amp;roll;

name:=&amp;name;

proc_Grade(roll, name);

End;

Enter value for roll: 1

old 5: roll:=&amp;roll;
new 5: roll:=1;

Enter value for name: &#39;yash&#39;

old 6: name:=&amp;name;

new 6: name:=&#39;yash&#39;;

PL/SQL procedure successfully completed.

SQL&gt; Declare

roll number;

name varchar(20);

Begin

roll:=&amp;roll;

name:=&amp;name;

proc_Grade(roll, name);

End;

Enter value for roll: 2

old 5: roll:=&amp;roll;

new 5: roll:=2;

Enter value for name: &#39;hrutvik&#39;

old 6: name:=&amp;name;

new 6: name:=&#39;hrutvik&#39;;

PL/SQL procedure successfully completed.


SQL&gt; Declare

roll number;

name varchar(20);

Begin

roll:=&amp;roll;

name:=&amp;name;

proc_Grade(roll, name);

End;

Enter value for roll: 3

old 5: roll:=&amp;roll;

new 5: roll:=3;

Enter value for name: &#39;paranv&#39;

old 6: name:=&amp;name;

new 6: name:=&#39;paranv&#39;;

PL/SQL procedure successfully completed.

SQL&gt; select * from result_26;

ROLL NAME CLASS

---------- -------------------- --------------------

1 yash Distinction
2 hrutvikHigher Second Class

3 paranv firstclass

You might also like