Cycle LLL
Cycle LLL
1. The hrd manager has decided to raise the employee salary by 15%. Write a pl/sql block to accept
the employee number and update the salary of that employee. Display appropriate message
based on the existence of the record in emp table.
SQL> BEGIN
WHERE EMPNO=&EMPNO;
ELSE
END IF;
END;
2. Write a pl/sql program to display top 10 rows in emp table based on their job and salary.
e emp2%rowtype;
begin
Cycle-3(pl/sql)
open c1;
loop
fetch c1 into e;
dbms_output.put_line('employee no:'||e.empno);
dbms_output.put_line('employee name'||e.ename);
dbms_output.put_line('*-*-*-*-*-*-*-*-*-*-*-*-*-*');
end loop;
end;
employee no:7839
employee nameKING
*-*-*-*-*-*-*-*-*-*-*-*-*-*
employee no:7788
employee nameSCOTT
*-*-*-*-*-*-*-*-*-*-*-*-*-*
employee no:7902
employee nameFORD
Cycle-3(pl/sql)
employee job is ANALYST
*-*-*-*-*-*-*-*-*-*-*-*-*-*
employee no:7566
employee nameJONES
*-*-*-*-*-*-*-*-*-*-*-*-*-*
employee no:7698
employee nameBLAKE
*-*-*-*-*-*-*-*-*-*-*-*-*-*
employee no:7782
employee nameCLARK
*-*-*-*-*-*-*-*-*-*-*-*-*-*
employee no:7499
employee nameALLEN
*-*-*-*-*-*-*-*-*-*-*-*-*-*
employee no:7844
employee nameTURNER
Cycle-3(pl/sql)
employee job is SALESMAN
*-*-*-*-*-*-*-*-*-*-*-*-*-*
employee no:7934
employee nameMILLER
*-*-*-*-*-*-*-*-*-*-*-*-*-*
employee no:7654
employee nameMARTIN
*-*-*-*-*-*-*-*-*-*-*-*-*-*
3. Write a pl/sql program to raise the employee salary by 10%, for department number 30 people
and also maintain the raised details in the raise table.
name varchar2(10),
desig varchar2(9),
mgr number(4),
doj date,
salary number(7,2),
comm number(7,2),
dno number(2));
Table created.
SQL> declare
e emp2%rowtype;
Cycle-3(pl/sql)
begin
open c2;
loop
fetch c2 into e;
end loop;
table');
close c2;
end;
table
6 rows selected.
Cycle-3(pl/sql)
4. Write a pl/sql procedure to prepare an electricity bill by using following table used: elect
NAME PREV_READ
NULL? NUMBER(5)
TYPE NO_UNITS
MNO NUMBER(5)
NUMBER(3) NUMBER(8,2)
CNAME SER_TAX
VARCHAR2(20) NUMBER(8,2)
CUR_READ NET_AMT
NUMBER(5)
NUMBER(9,2)
…………………………………………….
as
no_un elect.no_units%type;
amt elect.amount%type;
stax elect.ser_tax%type;
net elect.net_amt%type;
e elect%rowtype;
begin
open c9;
loop
fetch c9 into e;
no_un:=e.cur_read-e.prev_read;
Cycle-3(pl/sql)
amt:=no_un*1.5;
stax:=(5/100)*amt;
net:=amt+stax;
dbms_output.put_line('customer name'||e.cname);
end loop;
close c9;
end;
1 row created.
……….
………..
………
5. Write a pl/sql procedure to evaluate the grade of a student with following conditions: for
pass: all marks > 40 for i class: total%>59 for ii class: total%between>40 and <60 for iii class:
total%=40 Alsomaintain the details in abstract table. Tables USED
1. TABLE NULL? TYPE
STD NAME
---------------- -------- --------
NO NOT NULL NUMBER
NAME VARCHAR2(10)
INTNO NUMBER
CLASS NOT NULL VARCHAR
2(10)
M1 NUMBER
M2 NUMBER
Cycle-3(pl/sql)
M3 NUMBER
M4 NUMBER
M5 NUMBER
s1 std%rowtype;
total number(4);
grade1 varchar2(10);
per1 number(6,2);
begin
open stu_c;
loop
total:=s1.M1+s1.M2+s1.M3+s1.M4+s1.M5;
per1:=total/5;
grade1:='fail';
grade1:='||| class';
grade1:='| class';
end if;
end loop;
close stu_c;
end;
6 rows selected.
(house_no varchar2(10),
street varchar2(30),
city varchar2(20),
state varchar2(10),
Cycle-3(pl/sql)
pincode varchar2(10)
);
Type created.
DECLARE
residence address;
BEGIN
END;
SQL> /
Street: M.G.Road
City: Jaipur
State: Rajasthan
Pincode: 201301
ANS.
After trigger:
CREATE TABLE emp3
EMP_ID number(10),
SALARY number(10),
EMP_NAME varchar2(50)
Table created.
AFTER UPDATE
OF SALARY
ON emp3
DECLARE
username varchar2(20);
BEGIN
END;
Trigger created.
Cycle-3(pl/sql)
UPDATE employee_salary SET SALARY = '70000' WHERE emp_id = 101;
Instead of triggers:
CREATE TABLE employ
EMP_ID number(10),
SALARY number(10),
EMP_NAME varchar2(50)
Dept_no NUMBER,
Dept_name VARCHAR2(50),
LOCATION VARCHAR2(50))
BEGIN
COMMIT;
END;
/
Cycle-3(pl/sql)
PL/SQL procedure successfully completed.
BEGIN
COMMIT;
END;
Employee_name,dept_name,location) AS
SELECT employ.emp_name,dept2.dept_name,dept2.location
FROM EMPLOY,dept2
WHERE employ.dept_no=dept2.dept_no
View created.
INSTEAD OF UPDATE
ON emp3_view
BEGIN
Cycle-3(pl/sql)
UPDATE dept2
SET location=:new.location
WHERE dept_name=:old.dept_name;
END;
//Trigger created.
BEGIN
COMMIT;
END;