Write a PL/SQL Program to i.Hike the Employee salary as 100 if employee salary is in between 0 to 1000. ii.Hike the Employee salary as 200 if employee salary is in between 1001 to 2000. iii.Other than these two condition hike 300 insert the update employee details into the those table.
0
Write a PL/SQL Program to
i.Hike the Employee salary as 100 if employee salary is in between 0 to 1000.
ii.Hike the Employee salary as 200 if employee salary is in between 1001 to 2000.
iii.Other than these two condition hike 300 insert the update employee details into the those table.
SQL>DECLARE
TYPE eno IS TABLE OF
emp.empno%TYPE INDEX BY BINARY_INTEGER;
TYPE name IS TABLE OF
emp.ename%TYPE INDEX BY BINARY_INTEGER;
TYPE pays IS TABLE OF
emp.sal%TYPE INDEX BY BINARY_INTEGER;
e eno;
n name;
p pays;
ctl number:=1;
BEGIN
FOR i IN(SELECT empno,ename,sal FROM emp)
LOOP
e(ctl):=i.empno;
n(ctl):=i.ename;
p(ctl):=i.sal;
ctl:=ctl+1;
END LOOP;
for MyIndex IN 1..e.count
LOOP
IF p(MyIndex) BETWEEN 0 AND 1000 THEN
p(MyIndex):=p(MyIndex)+100;
ELSIF p(MyIndex) BETWEEN 1001 AND 2000 THEN
p(MyIndex):=p(MyIndex)+200;
ELSE
p(MyIndex):=p(MyIndex)+300;
END IF;
UPDATE emp SET sal=p(MyIndex)
WHERE empno=e(MyIndex);
INSERT INTO trace VALUE(n(MyIndex),p(MyIndex),sysdate);
Display(n(MyIndex)||’ ‘||p(MyIndex));
END LOOP;
END;
i.Hike the Employee salary as 100 if employee salary is in between 0 to 1000.
ii.Hike the Employee salary as 200 if employee salary is in between 1001 to 2000.
iii.Other than these two condition hike 300 insert the update employee details into the those table.
SQL>DECLARE
TYPE eno IS TABLE OF
emp.empno%TYPE INDEX BY BINARY_INTEGER;
TYPE name IS TABLE OF
emp.ename%TYPE INDEX BY BINARY_INTEGER;
TYPE pays IS TABLE OF
emp.sal%TYPE INDEX BY BINARY_INTEGER;
e eno;
n name;
p pays;
ctl number:=1;
BEGIN
FOR i IN(SELECT empno,ename,sal FROM emp)
LOOP
e(ctl):=i.empno;
n(ctl):=i.ename;
p(ctl):=i.sal;
ctl:=ctl+1;
END LOOP;
for MyIndex IN 1..e.count
LOOP
IF p(MyIndex) BETWEEN 0 AND 1000 THEN
p(MyIndex):=p(MyIndex)+100;
ELSIF p(MyIndex) BETWEEN 1001 AND 2000 THEN
p(MyIndex):=p(MyIndex)+200;
ELSE
p(MyIndex):=p(MyIndex)+300;
END IF;
UPDATE emp SET sal=p(MyIndex)
WHERE empno=e(MyIndex);
INSERT INTO trace VALUE(n(MyIndex),p(MyIndex),sysdate);
Display(n(MyIndex)||’ ‘||p(MyIndex));
END LOOP;
END;
0 comments: