Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

PL/SQL Control Statement Exercises: Insert records from one table to another

PL/SQL Control Statement: Exercise-29 with Solution

Write a program in PL/SQL to insert records from one table to another.

Sample Solution:

PL/SQL Code:

DROP TABLE emp_temp;
CREATE TABLE emp_temp (
  emp_id      NUMBER,
  emp_email  VARCHAR2(40)
);
 
DECLARE
  number_of_emp  NUMBER;
BEGIN
  SELECT COUNT(employee_id) INTO number_of_emp
  FROM employees;
  
  FOR i IN 1..number_of_emp LOOP
    INSERT INTO emp_temp (emp_id, emp_email)
    VALUES(i, 'not available now');
  END LOOP;
END;
/

Flowchart:

Flowchart: Insert records from one table to another.

Sample Output:

PL/SQL procedure successfully completed.

If you execute the command "select * from emp_temp;" you will see the data of emp_temp table.

Improve this sample solution and post your code through Disqus

Previous: Write a program in PL/SQL to check whether a number is prime or not using goto statement with for loop.
Next: Write a program in PL/SQL to insert a row if the featched value for a component is specified.

What is the difficulty level of this exercise?