w3resource

PL/SQL Control Statement Exercises: Insert a row if the featched value for a component is specified

PL/SQL Control Statement: Exercise-30 with Solution

Write a program in PL/SQL to insert a row if the featched value for a component is specified.

Sample Solution:

PL/SQL Code:

DROP TABLE TEST;
CREATE TABLE TEST(
c1 INTEGER,
c2 INTEGER);

DELETE FROM TEST;
INSERT INTO TEST VALUES(2, 4);
INSERT INTO TEST VALUES(1, 3);


DECLARE
    n1 NUMBER;
    n2 NUMBER;
BEGIN
    SELECT c1,c2 INTO n1,n2 FROM TEST WHERE c1>1;
   IF n2=4 THEN
        INSERT INTO TEST VALUES(n2,n1);
    ELSE
        INSERT INTO TEST VALUES(n2+15,n1+15);
    END IF;
END;
/

Flowchart:

Flowchart: Insert a row if the featched value for a component is specified.

Sample Output:

PL/SQL procedure successfully completed.

To see the inserted row use the command "select * from test;"

Improve this sample solution and post your code through Disqus

Previous: Write a program in PL/SQL to insert records from one table to another.
Next: PL/SQL Cursor Exercises.

What is the difficulty level of this exercise?



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/plsql-exercises/control-statement/plsql-control-statement-exercise-30.php