Unit 5

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

//Create a cursor that display all employees from emp table.

Old Table name : Employee (emp_id,


emp_name, salary,contact) New table name : Emp_new( emp_id, emp_name, salary,contact)

-- Assuming Employee and Emp_new tables already exist

DECLARE

CURSOR emp_cursor IS

SELECT emp_id, emp_name, salary, contact

FROM Employee;

v_emp_id Employee.emp_id%TYPE;

v_emp_name Employee.emp_name%TYPE;

v_salary Employee.salary%TYPE;

v_contact Employee.contact%TYPE;

BEGIN

FOR emp_rec IN emp_cursor

LOOP

v_emp_id := emp_rec.emp_id;

v_emp_name := emp_rec.emp_name;

v_salary := emp_rec.salary;

v_contact := emp_rec.contact;

-- Display employee details

DBMS_OUTPUT.PUT_LINE('Employee ID: ' || v_emp_id || ', Employee Name: ' || v_emp_name || ',
Salary: ' || v_salary || ', Contact: ' || v_contact);

-- Insert into Emp_new table

INSERT INTO Emp_new (emp_id, emp_name, salary, contact)

VALUES (v_emp_id, v_emp_name, v_salary, v_contact);

END LOOP;

COMMIT; -- Commit the transaction

DBMS_OUTPUT.PUT_LINE('Data inserted into Emp_new.');

END;

You might also like