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

Modify your solution to question 4 above, replacing the IF statement with an EXI

ID: 3747032 • Letter: M

Question

Modify your solution to question 4 above, replacing the IF statement with an EXIT....WHEN statement.

Create a MESSAGES table and insert several rows into it.

To create the messages table.

DROP TABLE messages;

CREATE TABLE messages (results NUMBER(2));

Write a PL/SQL block to insert numbers into the MESSAGES table. Insert the numbers 1 through 10, excluding 6 and 8.

DECLARE

V_numbero number(2):=1;

Begin

Loop

If v_numbre number<>6 and v_numbre<>8 then

Insert into messages(results)
values(v_numbre);

End if;

V_numbre:=v__numbre+1;

Exit when v_numbre>10;

End loop;

End;

   

   

       

Execute a SELECT statement to verify that your PL/SQL block worked

Explanation / Answer

Please find the modifed PL/SQL block below.

DECLARE

V_numbero number(2):=1;

BEGIN

LOOP

IF V_numbero number<>6 and V_numbero<>8 THEN

INSERT INTO messages(results) VALUES(V_numbero);

END IF;

V_numbero := V_numbero + 1;

EXIT WHEN V_numbero > 10;

END LOOP;

END;

Now, run a SELECT query on the messages table as given below.

SELECT * FROM messages;

NOTE: If the insertion happened successfully,the SELECT query will return 8 rows for 1, 2, 3, 4, 5, 7, 9, 10.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote