Rdbms Lab
Rdbms Lab
i)PL/SQL program using only an implicit cursor to select data from a table and print it.
DECLARE
v_employee_id employees.employee_id%TYPE;
v_first_name employees.first_name%TYPE;
v_last_name employees.last_name%TYPE;
BEGIN
FOR rec IN (SELECT employee_id, first_name, last_name FROM employees WHERE
department_id = 10) LOOP
v_employee_id := rec.employee_id;
v_first_name := rec.first_name;
v_last_name := rec.last_name;
Output
Employee ID: 101, Name: John Doe
Employee ID: 102, Name: Jane Smith
Employee ID: 103, Name: Alice Johnson
Program Using Explicit Cursor
ii)PL/SQL program that uses only an explicit cursor to select data from a table and print it.
DECLARE
-- Declare the explicit cursor
CURSOR emp_cursor IS
SELECT employee_id, first_name, last_name FROM employees WHERE department_id =
10;
output:
-- Insert a new employee; the trigger will automatically update the salary
INSERT INTO employees (employee_id, name, salary, department)
VALUES (1, 'John Smith', 50000, 'Sales');
INSERT INTO employees (employee_id, name, salary, department)
VALUES (2, 'Jane Doe', 60000, 'Marketing');
Output
Output :