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:
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?
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework