Question1,2,3 Ass5
Question1,2,3 Ass5
Write a PL/SQL stored Procedure for following requirements and call the procedure in
2. Fine(Roll_no,Date,Amt)
Check the number of days (from date of issue), if days are between 15 to 30 then fine
If no. of days>30, per day fine will be Rs 50 per day & for days less than 30, Rs. 5 per
day.
If condition of fine is true, then details will be stored into fine table.
is
mdate date;
mfine number(10);
datediff number(10);
begin
roll_no=mroll;
datediff:=to_date(sysdate)-to_date(mdate);
if(datediff<15) then
dbms_output.put_line('No Fine');
roll_no=mroll;
mfine:=(datediff*5);
dbms_output.put_line('Fine is '||mfine);
elsif(datediff>30) then
mfine:=((datediff-30)*50+(30*5));
dbms_output.put_line('Fine is'||mfine);
end if;
commit;
end;
declare
mroll number;
mbook varchar(20);
begin
mroll:=&mroll;
assign5_proc(mroll);
end;
output
No errors.
SQL> declare
2 mroll number;
3 mbook varchar(20);
4 begin
5 mroll:=&mroll;
6 assign5_proc(mroll);
8 end;
9 /
old 5: mroll:=&mroll;
new 5: mroll:=21;
PL/SQL procedure successfully completed.
SQL> 25
SQL> /
old 5: mroll:=&mroll;
new 5: mroll:=25;
SQL> /
old 5: mroll:=&mroll;
new 5: mroll:=26;
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
inactive”.
return number
is
mbranch number(15);
mstat char;
begin
select branch_no, status into mbranch, mstat from acc_26 where acc_no = macc;
return 1;
else
return 0;
end if;
end;
declare
macc number;
res number;
begin
macc := &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
end;
output
Account is active!
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
distinction category if marks scored are between 989 and900 category is first class, if
marks
Write a PL/SQL block for using procedure created with above requirement.
Stud_Marks(name, total_marks)
Result(Roll,Name, Class)
NAME MARKS
---------- ----------
yash 96
hrutvik 65
pranv 85
is
mtotal_marks number;
Begin
else
end if;
End;
Declare
roll number;
name varchar(20);
Begin
roll:=&roll;
name:=&name;
proc_Grade(roll, name);
End;
old 5: roll:=&roll;
new 5: roll:=1;
old 6: name:=&name;
new 6: name:='yash';
SQL> Declare
roll number;
name varchar(20);
Begin
roll:=&roll;
name:=&name;
proc_Grade(roll, name);
End;
old 5: roll:=&roll;
new 5: roll:=2;
old 6: name:=&name;
new 6: name:='hrutvik';
roll number;
name varchar(20);
Begin
roll:=&roll;
name:=&name;
proc_Grade(roll, name);
End;
old 5: roll:=&roll;
new 5: roll:=3;
old 6: name:=&name;
new 6: name:='paranv';
1 yash Distinction
2 hrutvikHigher Second Class
3 paranv firstclass