0% found this document useful (0 votes)
169 views10 pages

Experiment-3 DBMS

The document describes several PL/SQL programs that perform various operations: 1) A program that calculates HRA, DA, gross pay and net pay for employees based on their basic salary. 2) A trigger that prevents updating an employee's salary if it is less than 5000. 3) A trigger that generates a message if an employee's DA exceeds their salary and merges the DA with the basic salary. 4) A program that generates a message if an employee is reaching retirement age in the current month. 5) A program that deducts 6000 as CM relief fund from salaries, sets any negative salaries to 1000, and adjusts deductions accordingly. 6) A program that uses

Uploaded by

NANDHAKUMAR V M
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)
169 views10 pages

Experiment-3 DBMS

The document describes several PL/SQL programs that perform various operations: 1) A program that calculates HRA, DA, gross pay and net pay for employees based on their basic salary. 2) A trigger that prevents updating an employee's salary if it is less than 5000. 3) A trigger that generates a message if an employee's DA exceeds their salary and merges the DA with the basic salary. 4) A program that generates a message if an employee is reaching retirement age in the current month. 5) A program that deducts 6000 as CM relief fund from salaries, sets any negative salaries to 1000, and adjusts deductions accordingly. 6) A program that uses

Uploaded by

NANDHAKUMAR V M
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/ 10

EXPERIMENT – 3

1) Calculate hra,da, gross and net by using PL/SQL program.


BASIC HRA DA

15000 12% 8%
12000 10% 6%
9000 7% 4%
OTHERS 5% 200/-

PL/SQL PROGRAM:
DECLARE
BASIC NUMBER;
HRA NUMBER;
DA NUMBER;
NET NUMBER;
BEGIN
BASIC := &BASIC_SALARY;
IF BASIC > 15000 THEN
HRA := BASIC * .12;
DA := BASIC * .08;
ELSIF BASIC > 12000 THEN
HRA := BASIC * .1;
DA := BASIC * .06;
ELSIF BASIC > 9000 THEN
HRA := BASIC * .07;
DA := BASIC * .04;
ELSE
HRA := BASIC * .05;
DA := BASIC * 200;
END IF;
NET := BASIC + HRA + DA;
DBMS_OUTPUT.PUT_LINE ('BASIC: ' || BASIC);
DBMS_OUTPUT.PUT_LINE ('HRA: ' || HRA);
DBMS_OUTPUT.PUT_LINE ('DA: ' || DA);
DBMS_OUTPUT.PUT_LINE ('NET: ' || NET);
END;

EXPECTED OUTPUT:
pl/sql procedure successfully completed

OUTPUT:
2) Whenever salary is updated and its value becomes less than 5000 a trigger
has to be raised preventing the operation.

PL/SQL PROGRAM
Create or replace trigger sal
Before insert or update on emp11
for each row
begin
if :new.sal<5000 then
raise_application_error(-20456,'the 5000 below sal not accepted');
end if;
end;

EXPECTED OUTPUT:
pl/sql procedure successfully completed

OUTPUT:

3) When the da becomes more than 100%, a message has to be generated


and with user permission da has to be merged with basic.

PL/SQL PROGRAM

Create or replace trigger da1


Before insert or update on employee
for each row
begin
if :new.da>sal then
raise_application_error (-20456,'the da is not accepted, so the da is merge to basic’);
end if;
end;
EXPECTED OUTPUT:
Trigger Created Successfully.
OUTPUT:

4) If the employee is going to retire in a particular month, automatically a


message has to be generated.

PL/SQL PROGRAM:

DECLARE
v_dob DATE:=&amp;v_dob;
v_your_age
NUMBER(3,1)
Emp_name
varchar2(10);
BEGIN
v_your_age:= TRUNC (MONTHS_BETWEEN(SYSDATE,v_dob))/12;
DBMS_OUTPUT.PUT_LINE (&#39;Your age is&#39;|| v_your_age);
IF
v_your_age&gt;65
THEN

DBMS_OUTPUT.PUT_LINE(&#39;YOU ARE GOING TO RETAIRE IN THIS MONTH&#39;);


END IF;
END;
EXPECTED OUTPUT:
pl/sql procedure successfully completed
OUTPUT:
5) Amount 6000 has to be deducted as CM relief fund in a particular month
which has to be accepted as input from the user. Whenever the salary becomes
negative it has to be maintained as 1000 and the deduction amount for those
employees is reduced appropriately.

PL/SQL program:

Create table kcb_acc_tab (accno number(10),acctype varchar2(20),bal

number(10));

create table kcb_tran_tab(sno number(10),accno number(10),ttype varchar2(20),

date_of_tran

date, amt number(10));

create sequence s1

increment by 1

start with 1

Maxvalue 100

Nocycle

Nocache;

Create or replace procedure upd_bal (paccno in kcb_acc_tab.accno%type,pttype in


kcb_tran_tab.ttype%type,pamt in kab_tran_tab.amt%type)
Is
cbal kcb_acc_tab.bal%type;
vacctype kcb_acc_tab.acctype%type;
Begin
Select acctype,bal into vacctype,cbal from kcb_acc_tab where accno=paccno;
If pttype=&#39;D&#39; then
cbal:=cbal+pamt;
Else if pttype=&#39;w&#39; then
cbal:=cbal-pamt;
End if;
If vacctype =&#39;S&#39; and cbal &lt; 1000 then
Raise_application_error(-20345,&#39;the bal is too low. so no transaction&#39;);
Else if vacctype =&#39;C&#39; and cbal&lt;1000 then
Raise_application_error(-20346,&#39;the bal is too low. so no transaction&#39;);
End if;
Update kcb_acc_tab set bal=cbal where accno=paccno;
Insert into kcb_tran_tab values(s1.nextval,paccno,&#39;D&#39;,sysdate,pamt);
Commit;
Exception
WHEN NO_DATA_FOUND THEN
Dbms_output.put_line(paccno|| ‘is not exist’);
End upd_bal ;

EXPECTED OUTPUT:
Exec(1001,D,6000);
OUTPUT:
6) As a designer identify the PL/SQL procedures necessary and create them using
cursors.
PL/SQL program
DECLARE CURSOR C1 IS SELECT EMPNO,ENAME ,DEPTNO
FROM EMP;EMPNUM EMP.EMPNO%TYPE;

EMPNAME EMP.ENAME%TYPE;
DEPTNUM EMP.DEPTNO%TYPE;
BEGIN

OPEN C1;
LOOP

FETCH C1 INTO EMPNUM,EMPNAME,DEPTNUM;


if c1%notfound then
exit;

else
dbms_output.put_line(EMPNUM||' '||EMPNAME||' '||DEPTNUM);
end if;

END LOOP;
end;

EXPECTED OUTPUT:
PL/SQL Procedure successfully Created

OUTPUT:

You might also like