Assignment: SYBCA-DIV-1-SEM-3 Rdbms Roll No-77
Assignment: SYBCA-DIV-1-SEM-3 Rdbms Roll No-77
Assignment: SYBCA-DIV-1-SEM-3 Rdbms Roll No-77
ASSIGNMENT
1.write pl/sql program to accept user salary& calculation of net salary and
display it.
Da =15% HRA=41%
Net salary:=basic+da+hra-pf
Ans:
Declare
Salary number(4);
Da number(4);
Hra number(4);
Pf number(4);
Net number(4);
Temp number(4);
Begin
Salary:=&salary;
Net:=0;
Page 1
SYBCA-DIV-1-SEM-3 RDBMS ROLL NO-77
If salary<3000 then
Pf:=5;
Pf:=7;
Pf:=8;
Pf:=10;
End if;
DA:=15;
HRA:=41;
NET:=net+salary;
Temp:=(salary*da)/100;
Net:=net+temp;
Temp:=(salary*hra)/100;
Net:=net+temp;
Temp:=(salary*pf)/100;
Net:=net-temp;
Dbms_output.put_line(‘net salary=’llnet);
End ;
Page 2
SYBCA-DIV-1-SEM-3 RDBMS ROLL NO-77
/
OUTPUT
Enter value for basic: 25000
old 2: basic number(7):=&basic;
new 2: basic number(7):=25000;
Net salary : 36500
Ans:
Emp_no number(5),
Emp_name varchar(10),
Emp_salary number(5)
);
Declare
Empno number(5);
Salary number(5);
Page 3
SYBCA-DIV-1-SEM-3 RDBMS ROLL NO-77
Begin
Empno:=&empno;
Where emp_no=empno;
If sal>5000 then
Update employee
Set emp_salary=emp_salary+1000
Where emp_no=empno;
End if;
Goto print_table;
<<print_table>>
End;
/
OUTPUT
select*from emp;
NO NAME SALARY
1 mahesh 10000
2 shital 4000
3 pinal 90000
4 yashvi 505000
5 jaimin 78000
Page 4
SYBCA-DIV-1-SEM-3 RDBMS ROLL NO-77
3.write pl/sql code block accept empno from user and display record of
particular emp details.emp(empno,name,salary)
Ans:
Empno number(4),
Name varchar(30),
Salary number(10)
);
Commit;
Declare
R emp% rowtype;
Emp number(10);
Begin
Emp:=&emp;
End;
/
OUTPUT
4.write pl/sql code block empno from user and check salary is greater then 1000
display rexcord.emp details also display message salary is not greater and emp is
not found.
Ans:
Empno number(4),
Name varchar2(10),
Salary number(10)
);
Declare
R emp1% rowtype;
No number(3);
Begin
No:=&no;
If r.salary>=1000 then
Else
End;
/
OUTPUT
Enter value for empno: 3
old 2: empno emp.empno%type:=&empno;
new 2: empno emp.empno%type:=3;
Empno :3
Page 7
SYBCA-DIV-1-SEM-3 RDBMS ROLL NO-77
Name : tina
Salary :4000
5.write a pl/sql code block that will accept an employee number from user and
deduct salary by rs 5000……
Ans:
No number,
Name varchar2(20),
Salary number(30)
);
Commit;
Declare
Sal emp.salary%type;
Nu number(2);
Page 8
SYBCA-DIV-1-SEM-3 RDBMS ROLL NO-77
Begin
Nu:=ν
Sal:=sal-5000;
Else
Commit;
End if;
Exception
End;
/
OUTPUT
6.write a prog which will raise customer exception when deleting record in emp
table…..
Page 9
SYBCA-DIV-1-SEM-3 RDBMS ROLL NO-77
Ans:
No number(10),
Name varchar2(20),
Salary number(20)
);
Commit;
Declare
Del exception;
R emp%rowtype;
Begin
Open mycursor;
Page 10
SYBCA-DIV-1-SEM-3 RDBMS ROLL NO-77
Loop
Fetch mycursor%notfound;
If r.salary>5000
Commit;
Else
Raise del;
End if;
Exception
End;
Ans:
Emp_no number(5),
Emp_name varchar2(10),
Page 11
SYBCA-DIV-1-SEM-3 RDBMS ROLL NO-77
Date_of_join date,
Emp_sal_number(5)
);
Declare
Empno number(5);
Empname varchar(10);
Dateofjoin date;
Empsal number(5);
Less_exception;
Pragma exception_init(less_,-20001);
Begin
Empno:=&empno;
Empname:=’&empname’;
Dateofjoin:=’&dateofjoin’;
Empsal:=&empsal;
If empsal<5000 then
Raise less_;
Else
Page 12
SYBCA-DIV-1-SEM-3 RDBMS ROLL NO-77
End if;
Exception
When less_then
End;
/
OUTPUT
8.Create procedure which take as argument dno,ino and return total quantity
sold by distributor for this particular item.
distributer(dno,dname,dadress,dphno) item(ino,iname,colour,weight)
dist_item(dno,ino,qty)
Ans:
create or replace procedure
dist(a IN number, b IN number) as
dqty dist_item.qty%type:=0;
Page 13
SYBCA-DIV-1-SEM-3 RDBMS ROLL NO-77
cursor c1 is select * from dist_item where dno=a and ino=b;
begin
for rec in c1
loop
dqty:=dqty+rec.qty;
dbms_output.put_line(a||' '||b||' '||rec.qty);
end loop;
end;
/
declare
a Dist_item.dno%type:='&a';
b Dist_item.ino%type:='&b';
begin
dist(a, b);
end;
/
Enter value for a: 2
Enter value for b: 12 2 12 9
9.Write a procedure to display name of employee who are earning less then
20000 and born before 30 years. Emp(eno,ename,date-of-birth,salary)
Ans:
create or replace procedure sal_age is
Page 14
SYBCA-DIV-1-SEM-3 RDBMS ROLL NO-77
cursor c1 is select eno,name,(sysdate-dob)/365 "age" from emp where salary<20000
and ((sysdate- dob)/365)>30;
begin
for rec in c1 5 loop
dbms_output.put_line(rec.eno||' '||rec.name);
end loop;
end;
/
execute sal_age; E3 ankit
10.Write a procedure that is passed a student rollno and return back to student
name and phone no from the student table by calling procedure in PL/SQL
block. Student(rollno,name,age,phno,marks)
Ans:
create or replace procedure stud(no in number,nm out varchar2,ph out number) is
begin
select name,phno into nm,ph from student where no=rollno;
end;
/
declare
no student.rollno%type;
nm student.name%type;
ph student.phno%type;
begin
Page 15
SYBCA-DIV-1-SEM-3 RDBMS ROLL NO-77
no:=&no;
stud(no,nm,ph);
dbms_output.put_line('rollno'||' '||'name'||' '||'phno');
dbms_output.put_line(no||' '||nm||' '||ph);
end;
/
Enter value for no: 1 rollno name phno
1 royal 8354638234
Page 17
SYBCA-DIV-1-SEM-3 RDBMS ROLL NO-77
13.Write a database trigger that will not allow the changes to the salary of
employees who are having an experience less than 3 years.
emp(eno(P.K.),name,salary,exp)
Ans:
create or replace trigger exp before update on emp for each row
begin
if((sysdate - :old.exp)/365)<3 then
raise_application_error(-20001,'can not change salary because an experience is less
than 3 years'); end if;
end;
/
14.Create trigger that will not allow update of salary for employee who are in
sales department Emp(no,name,dno,salary,designamtion)
Dept(dno,name,location)
Ans:
create or replace trigger sal_emp
before update of salary on emp for each row
declare
pragma autonomous_transaction;
nm varchar2(20);
begin
select d.dname into nm from dept d,emp e where e.dno=d.deptno;
if nm='sales' then
raise_application_error(-20001,'can not update salary');
end if;
Page 18
SYBCA-DIV-1-SEM-3 RDBMS ROLL NO-77
end;
/
OUTPUT
Update emp set salary=59000 where no:=55;
ERROR at line 1:
ORA-2001:can not update salary because sales department
15.Write a database trigger that not allowing change emp table after the
business hours (from 8:00 a.m. to 5:00 P.m.) from Monday to Saturday.
emp(eno(P.K.),name,salary).
Ans:
create or replace trigger tr1
before insert or update or delete on emp 3 begin
if (rtrim(to_char(sysdate, 'day')) = 'sunday')
then
raise_application_error(-20002, 'Cannot use on sunday');
elsif to_char(sysdate,'hh24')<9 or to_char(sysdate,'hh24')>17
then
raise_application_error(-20001,'can not do any changes because business time is
over');
end if;
end;
/
OUTPUT
Trigger created.
Page 19
SYBCA-DIV-1-SEM-3 RDBMS ROLL NO-77
SQL> UPDATE EMP SET NAME='PALAK' WHERE NO:=52;
UPDATE EMP SET NAME='PALAK' WHERE NO:52 *
ERROR at line 1:
ORA-00920: invalid relational operator
Page 20