0% found this document useful (0 votes)
13 views3 pages

Modern College of Engineering, Pune: MCA Department A.Y.2023-24

The document describes two PL/SQL code blocks. The first inserts a record into an emp table, updates the salary by Rs. 2000, and checks if the total salary exceeds Rs. 20000 to undo the updates. The second accepts an employee number, updates the salary by 0.15%, and displays messages based on if the employee record exists.

Uploaded by

personalpcemail
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)
13 views3 pages

Modern College of Engineering, Pune: MCA Department A.Y.2023-24

The document describes two PL/SQL code blocks. The first inserts a record into an emp table, updates the salary by Rs. 2000, and checks if the total salary exceeds Rs. 20000 to undo the updates. The second accepts an employee number, updates the salary by 0.15%, and displays messages based on if the employee record exists.

Uploaded by

personalpcemail
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/ 3

Progressive Education Society's

Modern College of Engineering, Pune


MCA Department
A.Y.2023-24
(310917) Database Management System Laboratory
*********************************************************************************************
Class: FY-MCA Shift / Div.: F2/B Roll Number : 51146

Name: Aniket R Rajput Assignment No: 08 Date of Implementation: 13/03/2024

*********************************************************************************************

Q1. Write a PL/SQL block of code that first inserts a record in an ‘emp’ table. Update the salary by Rs. 2000. Then

check to see that the total salary does not exceed 20000. if so, undo the updates made to the salaries.

Ans.:

Query:

SET SERVEROUTPUT ON;

DECLARE old_sal

emp.sal%TYPE:=0; temp_sal

emp.sal%TYPE:=0;

BEGIN

INSERT INTO emp VALUES(7111,'BOB','SALESMAN',7698,'12-JUN-

90',19000,1000,30); dbms_output.put_line('INSERTED DATA INTO EMP

TABLE'); SELECT sal INTO old_sal FROM emp WHERE empno=7111;

UPDATE emp33 SET sal=old_sal+2000 WHERE empno=7111;

dbms_output.put_line('UPDATED SALARY OF EMPLOYEE TO ' || old_sal);

SELECT sal INTO temp_sal FROM empWHERE empno=7111;

IF temp_sal>20000 THEN dbms_output.put_line('REVERTING TO OLD SALARY AS SALARY IS GREATER THAN 20000.

OLD SALARY : ' || old_sal); UPDATE empSET sal=old_sal WHERE empno=7111;

END IF;
END;
OUTPUT:

Q2. HRD manager has decided to raise the salary of employees by 0.15. Write a PL/SQL block to accept the employee

number update the salary of that emp. Display message based on the existence of record in employee table.

Ans.:

Query:

DECLARE emp_no emp.empno%TYPE :=

:emp_no; old_sal emp.sal%TYPE := 0;

emp_name emp.ename%TYPE;

BEGIN

SELECT ename, sal INTO emp_name, old_sal FROM emp WHERE empno = emp_no;

dbms_output.put_line('BEFORE UPDATING SALARY');

dbms_output.put_line('Employee name: ' || emp_name);

dbms_output.put_line('Old salary: ' || old_sal);

UPDATE emp33 SET sal=(old_sal+(old_sal*0.15)) WHERE empno = emp_no; SELECT

ename, sal INTO emp_name, old_sal FROM emp WHERE empno = emp_no;

dbms_output.put_line('AFTER UPDATING SALARY');

dbms_output.put_line('Employee name: ' || emp_name);

dbms_output.put_line('New salary: ' || old_sal);

END;
OUTPUT:
*****************************************************************************************************
****************************************************************************************************

You might also like