Write a program in PL/SQL to insert data into two tables from one table using an implicit cursor

  • pl/sql

Write a program in PL/SQL to insert data into two tables from one table using an implicit cursor.

الأجوبة

DROP TABLE emp_temp;
CREATE TABLE emp_temp AS
  SELECT employee_id, department_id,job_id
  FROM employees;
DELETE FROM emp_temp;
COMMIT; 

DROP TABLE emp_detls_temp;
CREATE TABLE emp_detls_temp(
employee_id NUMBER,
empname varchar2(40)); 


DECLARE

    CURSOR cur_stclerk IS
      SELECT employee_id,
	         department_id,
             first_name,
             last_name
      FROM   employees
      WHERE  job_id = 'ST_CLERK';
BEGIN
FOR z_employeeinfo IN cur_stclerk	
    LOOP
        INSERT INTO emp_temp
                    (employee_id,
                     department_id,
                     job_id)
        VALUES      (z_employeeinfo.employee_id,
                     z_employeeinfo.department_id,
                     'ST_CLERK');

        INSERT INTO emp_detls_temp
                    (employee_id,
                     empname)
        VALUES      (z_employeeinfo.employee_id,
                     z_employeeinfo.first_name
                     || ' '
                     ||z_employeeinfo.last_name);
    END LOOP;
    COMMIT; 
END;
/

Sample Output:

PL/SQL procedure successfully completed.

If you want to see the inserted data from the table emp_temp and emp_detls_temp type the following statement:

select * from emp_temp;
select * from emp_detls_temp;
هل كان المحتوى مفيد؟

معلومات ذات صلة

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...