0% found this document useful (0 votes)
3 views2 pages

Exp 11 CURSOR

The document describes a PL/SQL script that retrieves employee data from a table, outputs their SSNs and names, and updates total salaries based on basic pay and allowances. It includes the creation of an Employee table and the insertion of employee records. The final output shows the updated total salaries for each employee after the calculations.

Uploaded by

mahigireesh09
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Exp 11 CURSOR

The document describes a PL/SQL script that retrieves employee data from a table, outputs their SSNs and names, and updates total salaries based on basic pay and allowances. It includes the creation of an Employee table and the insertion of employee records. The final output shows the updated total salaries for each employee after the calculations.

Uploaded by

mahigireesh09
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

SET SERVEROUTPUT ON;

DECLARE
id Employee46.ssn % type;
name Employee46.frame % type;
cursor c1 is rated ssn, frame from Employee46;
BEGIN
OPEN C1;
loop
fetch c1 into iid, name;
exit when c1% not found;
dbms_output.put_line (id ||'' || name);
end loop;
close c1;
END;
123456789 John
333445555 Franklin
999887777 Alicia
987654321 Jennifer
666884444 Ramesh
458453453 Joyce
787847857 Ahmad
888665555 James

PL/SQL procedures successfully completed.

2. CREATE TABLE Employee Employee - number INT PRIMARY KEY,basic_pay


NUMBER(10), allowance NUMBER(10), total_salary number(10);
INSERT INTO Employee VALUES (101, 5000, 2000, 0);
INSERT INTO Employee VALUES (102, 6000, 1000, 0);
INSERT INTO Employee VALUES (103, 8000, 1500, 0);
SELECT * from Employee;
EMPLOYEE_NUMBER BASIC_PAY ALLOUANCE TOTAL_SALARY
--------------- --------- ---------- ------------
101 5000 2000 0
102 6000 1000 0
103 8000 500 0

SET SERVEROUTPUT ON;


DECLARE
id Employer777.employee_number%type;
basic Employee777.basic_pay%type;
allow Employee777.allowance%type;
total Employee777.total_salary%type;
cursor c1 is select employee_number,basic_pay,allowance, total_salaxy FROM
Employee777;
BEGIN
open c1;
loop
Fetch c1 into id,basic,allow,total;
exit when c1%notfound;
update Employee777 set total_salaxy=basic+allowance where
employee_number=id;
end loop;
close c1;
END;
PH/SQL procedure successfully completed
select * FROM Employee777;

EMPLOYEE_NUMBER BASIC_PAY ALLOWANCE TOTAL_SALARY


--------------- --------- --------- ------------
101 5000 2000 7000
102 6000 1000 7000
103 8000 1500 9500

You might also like