PL/SQL Using the following code I need these problems finished. DECLARE v_recno
ID: 3761610 • Letter: P
Question
PL/SQL Using the following code I need these problems finished.
DECLARE
v_recno testloop.rec_no%TYPE :=1;
v_ctr testloop.ctr%TYPE :=1;
v_datain testloop.data_in%TYPE :=2;
BEGIN
WHILE v_recno < 6 LOOP
INSERT INTO testloop(rec_no, ctr, data_in)
VALUES(v_recno, v_ctr, v_datain);
v_recno :=v_recno + 1;
v_ctr :=v_ctr + 1;
v_datain :=v_recno + v_ctr;
END LOOP;
END; /
Problem #4: Now do a nested loop where each of the numbers you are adding is a separate variable controlled by its own loop. Do this using a WHILE structure. Note I am looking for something that starts with 1 + 1 = 2, 1 + 2 = 3, 1 + 3 = 4, 1 + 4 = 5 and then 2 + 1 = 2 etc with the final one being 4 + 4 = 8.
Problem #5: Redo #4 using a basic loop structure.
Problem #6: Redo #4 using a FOR loop.
Problem #7: You want to determine how many of a particular item can be purchased given the amount you have to spend. Clearly you need to establish the item price and how much you have to spend. The result on the screen should tell how many of that item you can purchase.
Problem #8: First create a table called amttopay that has three fields: rec_no, idno and amt (make amount a numeric field that can hold 3 decimal places. You are also going to use a copy of the donor table for this assignment. Take in a number that matches an idno on the donor table. Check the yrgoal for that record. If it is larger than 500 then double it to create a new goal and write four records on the amttopay table containing the quarterly payment number (1 through 4), the idno, and the quarterly amount to pay to achieve the new goal. If it is not larger than 500 then add 50% to the goal to make the new goal and process it by writing the four records with the same information.
Explanation / Answer
Problem #4:
DECLARE
v_recno testloop.rec_no%TYPE :=1;
v_ctr testloop.ctr%TYPE :=1;
v_datain testloop.data_in%TYPE :=2;
BEGIN
WHILE v_recno < 6 LOOP
INSERT INTO testloop(rec_no, ctr, data_in)
VALUES(v_recno, v_ctr, v_datain);
v_recno :=v_recno + 1;
v_ctr :=v_ctr + 1;
v_datain :=v_recno + v_ctr;
END LOOP;
END; /
Problem #5:
DECLARE
v_recno testloop.rec_no%TYPE :=1;
v_ctr testloop.ctr%TYPE :=1;
v_datain testloop.data_in%TYPE :=2;
BEGIN
WHILE v_recno < 6 LOOP
INSERT INTO testloop(rec_no, ctr, data_in)
VALUES(v_recno, v_ctr, v_datain);
v_recno :=v_recno + 1;
v_ctr :=v_ctr + 1;
v_datain :=v_recno + v_ctr;
END LOOP;
END; /
Problem #6:
DECLARE
v_recno testloop.rec_no%TYPE :=1;
v_ctr testloop.ctr%TYPE :=1;
v_datain testloop.data_in%TYPE :=2;
BEGIN
FOR v_recno IN 1 ... 6 LOOP
INSERT INTO testloop(rec_no, ctr, data_in)
VALUES(v_recno, v_ctr, v_datain);
v_recno :=v_recno + 1;
v_ctr :=v_ctr + 1;
v_datain :=v_recno + v_ctr;
END LOOP;
END; /
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.