Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

please help ( database ) Assignment 5 PL/SQL Assignment 2 Notice: be sure to exe

ID: 3730588 • Letter: P

Question

please help ( database )

Assignment 5
PL/SQL Assignment 2
Notice: be sure to execute the following command before you start working on the following
questions.
set serveroutput on;
1. Re-do the question 4 of the PL/SQL Assignement 1 by using loop control.
Hint: consider using VARRAY. For example
DECLARE
type gradeCount is varray(5) of integer;
gdcnt gradeCount;
type grade is varray(5) of char(1);
gd grade;

BEGIN
gdcnt := gradeCount(0,0,0,0,0);
gd := grade(‘A’, ‘B’, ‘C’, ‘D’, ‘F’);

END;
2. Type the following anonymous block and execute it.
DECLARE
sm binary_integer :=0;
i binary_integer :=0;
BEGIN
loop
i := i + 1;
if i > 10 then
exit;
end if;
sm := sm + i;
end loop;
dbms_output.put_line('sum= ' || sm || '.');
END;
3. Revise the above program by using for loop and while loop respectively, and
execute them. The revised program should have the same result as the above program.

Explanation / Answer

2.

DECLARE
sm binary_integer :=0;
i binary_integer :=0;
BEGIN
loop // loop starts
i := i + 1; // incrementing i by 1
if i > 10 then // checking the condition
exit;
end if;
sm := sm + i; // if condition is not satisfied, sm is added with i
end loop; // end of loop
dbms_output.put_line('sum= ' || sm || '.'); // printing the output
END;

Output

It will the sum of numbers from 1 to 9.

sum = 45

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

3. using For loop

DECLARE
sm binary_integer :=0;
i binary_integer :=0;
BEGIN
for i in 1...9 loop // loop starts, i takes values from 1 to 9
sm := sm + i; // sm is added with i
end loop; // end of loop
dbms_output.put_line('sum= ' || sm || '.'); // printing the output
END;

Output

sum = 45

using while loop

DECLARE
sm binary_integer :=0;
i binary_integer :=0;
BEGIN
while i <10 loop // loop starts, condition is also specifed
sm := sm + i; // sm is added with i

i=i+1; // incrementing the value of i
end loop; // end of loop
dbms_output.put_line('sum= ' || sm || '.'); // printing the output
END;

Output

sum = 45