EnggRoom Code Rdbms Program
EnggRoom Code Rdbms Program
1 Write a PL/SQL Block that calculate marks of three subjects and display the total by firing
that the database trigger while inserting the marks of three subjects.so total should automatically
calculated at the time of inserting marks of three subjects.
Design the database trigger to calculate the total while INSERT operation.
Table : Student (roll no,name,sub1,sub2,total)
Write a PL/SQL block to find out the factorial value using procedure and function call the
procedure and function in main code block.
DECLARE
num number(10);
factorial number(10);
FUNCTION fact(x number)
RETURN number
IS
f number(10);
BEGIN
IF x=0 THEN
f := 1;
ELSE
f := x * fact(x-1);
END IF;
RETURN f;
END;
BEGIN
num:= 6;
factorial := fact(num);
dbms_output.put_line(' Factorial '|| num || ' is ' || factorial);
END;
3 Write PL/SQL block to display employee details of each employee for the given deptno using
explicit cursor. (read the deptno from useer) (employee table :
empno,ename,job,hiredate,sal,commission,deptno)
Open C1(20)
LOOP
FETCH C1 INTO emp_row;
EXIT WHEN C1 %NOTFOUND;
END LOOP;
END;
5.Create a trigger,which will store the old information of employee after giving 15% raise to him.
Q.6 Write a PL/SQL block which will give a rise in salary to employee as per
the following rule.
If salary + comm < 5000 increase salary by 10%
If Salary + comm >= 5000 increase salary by Rs.500 and
If salary + Comm is above 7000 also increase salary by 12%
DECLARE
Salary number(15,2);
Empno number(10);
Comm number(10,2);
BEGIN
Select salary,eno,Comm from employee
If sql%found THEN
FOR row in sql
LOOP
Select sql.salary,sql.empno,sql.comm into Salary,Empno,comm.
Salary=salary+comm.;
If Salary<5000 then
Update Employee Set salary=salary+(salary*0.05) where empno=sql.empno ;
End if;
END LOOP;
END IF;
End;