1CS2010307 PLSQL
1CS2010307 PLSQL
Course Objective:
The objectives of the course are to:
To be able to understand the concepts of PL/SQL
To be able to understand various database objects stored procedure, function and Packages
To be able to understand about various database triggers
Subject Contents
Sr. Total Weight
Topic
No Hours (%)
Advance SQL
1 Hierarchical Queries, Advanced Queries (Running sum and Decode, Top N queries) 5 10
Indexes, Views, SEQUENCES
Introduction to PL/SQL
Overview, PL/SQL, Advantages of Pl/SQL, Generic
2 5 15
PL/SLQ Block
PL/SQL Fundamentals: PL/SQL Variables and PL/SQL
Data types, Variable attribute ( %type, %rowtype)
PL/SQL Control Structure (looping)
PL/SQL Cursor Management
Implicit Cursor, Cursor Attributes, Writing Explicit Cursors
3 (Cursor function, declaring, opening, fetching data from cursor), Cursor FOR loop. 5 10
Advanced Explicit Cursors ( Cursor with Parameter )
Error handling in PL/SQL & Security
Exception Types, Predefined Exception, User Defined
4 6 15
Exception, Raise_Application_Error.
Locks, Types of locks, Application of Locks
Application of Save Point, Commit and Rollback
PL/SQL Database Objects
Anonymous PL/SQL and named Block.
5 Developing Procedures, formal and actual parameters, IN, OUT and INOUT parameters. 5 15
Creating Functions, Stored Functions, User Defined Functions.
Creating Packages: - Component of Package, Developing Package, Package
Specification, Package Body.
Overloading procedures and Functions.
FACULTY OF COMPUTER SCIENCE
Master of Computer Application (Sem-III)
In Effect from Academic Year 2017-18
6 Triggers
Types of triggers, 5 15
Creating DML Triggers (Row trigger, Statement triggers, Before and after triggers,
Using OLD and NEW qualifier), Drop Trigger and Applications of Trigger.
7 Collection in PL/SQL 5 20
Object Types, Nested Tables, Variable Arrays, Associative
Arrays/ Index by table Array.
Course Outcome:
At the end of this course, the student would be able
o Ability to understand the concept of PL/SQL
o Ability to build and manage database objects like stored procedure,
Function and Package
o Ability to understand the usage of database triggers in application.
List of References
1. Ivan Byross, SQL, PL/SQL the programming Language of Oracle, BPB
2. P.S.Deshpande, SQL and PL/SQL for Oracle 11g”, Black Book, dreamtech publication.
3. Kevin Loney ,Oracle Database 11g :The Complete Reference, Oracle Press, McGrawHill
4. Ms. Anjali Jivani and Ms. Amisha Shingala , “ Practice book on SQL and PL/SQL with
examples”, Nirav and Roopal Publications, Third Edition.
Implicit cursor
EMP( empno, empnm, empadd, salary, date_birth, joindt, deptno)
DEPT(deptno, deptnm)
Note: Make table with appropriate constraints and insert proper data.
Explicit cursor
1. Write a PL/SQL block (table above EMP-DEPT table) which takes as input Department name
And displays all the employees of this department who has been working since last five years.
2. From the following schema , Write a PL/SQL for the following
a. Accept the Entrace test ID and test centre ID from the user and display
the details about all those applicants who has score more than average
for that test.
b. Also display the details about the dates on which the test centre has
full attendance.
c. Display details about the applicants and details of all the test the applicant
has appeared for with his scores.
FACULTY OF COMPUTER SCIENCE
Master of Computer Application (Sem-III)
In Effect from Academic Year 2017-18
NET PAY :
(a) For a given bill number, print the bill in the following format.
(b) Add one more attribute named bill_amount in the Bill table. Update the Bill table
to store bill amount.
5. Write a PL/SQL block, which will give a raise in salary to the employees as per the following:
USE above EMP table .
If salary + comm. < 5000 increase by 10% of salary
If salary + comm. >= 5000 increase by 500 + 12% of salary above 7000
Note : SELECT ... FOR UPDATE BEING USED IN CURSOR and CURSOR – FOR LOOP USED
FACULTY OF COMPUTER SCIENCE
Master of Computer Application (Sem-III)
In Effect from Academic Year 2017-18
For the above table, check which students have to pay fine and the amount of fine to be
paid. A student can keep the book for 15 days. If the number of days has exceeded
15 then, the fine is calculated as follows: Up
to 7 days : 50 paise per day
8 – 15 days : Re 1 per day (to be counted from the 8th day onwards) More
than 15 : Re 1.5 per day (to be counted from the 16th day onwards)
After calculating the fine store the required information in the FINE table so that a
report can later be printed out.
FINE (ROLLNO, BOOKNO, ISSUE_DATE, RETURN_DATE, TOT_DAYS, FINE)
8 Conside the patient schema as :
Prepare a report from above table taking date, shift, , doctor_id as parameters.
Shift is Morning if time are from 9.00 Am to 1.00 pm and
Shift is Evening if time are from 5.00 to 9.30 pm.
APPOINTMENT SCHEDULE
a. Write a procedure to print the Bank Transaction details by passing from and to dates.
2. Write a function that returns total number of incomplete jobs, using table
JOB(jobid, type_of_job, status)
3. Write a function which displays the number of items whose weight fall between a given range
for a particular color using table ITEM(itemno, name, color, weight)
4. Write a function which returns number of workers with same skills as that of the worker who
pass as a parameter using table WORKER(worker_id, name, wage_per_hour, specialization,
manager_id).
FACULTY OF COMPUTER SCIENCE
Master of Computer Application (Sem-III)
In Effect from Academic Year 2017-18
Write a procedure to display top five highest paid workers who are specialized in
“PAINTING”
Write a procedure which displays the details of doctor who has max. appointment. A
local function returns the doctor_id having max. appointment.
a. Write a trigger for insert or update to check that HRA should be more than 3000 and DA
should be in between 40 and 50.
b. Write a trigger to update temp table TEMP(tnm, tdt) whenever any data is inserted /
deleted / modified in EMP table.
c. Write a trigger which does not allow records of EMP to be deleted on 30th of any month.
FACULTY OF COMPUTER SCIENCE
Master of Computer Application (Sem-III)
In Effect from Academic Year 2017-18
3. Given a table
a. Write a trigger which allows only those items to be inserted which starts from ‘I’
Or ‘I’.
b. Write a trigger which check whether quantity ordered is less than quantity on hand
Before allowing that record to be inserted in ISSUE_ITEM table.
4. DEMP(EMP_ID, EMPNM)
DEPT(DEPT_ID,DNAME, DLIMIT) EMP_DEPT(EMP_ID, DEPT_ID)
A. WHILE TRANSFERING EMPLOYEE FROM ONE DEPT TO ANOTHER, CHECK THAT NUMBER
OF EMPLOYEE IN DEPT DOES NOT EXCEED THE LIMIT.
D. WRITE TRIGGER TO CHECK WHETHER EMP NAMES ARE INSERTED IN UPPERCASE, IF USER
GIVES IN LOWER CASE INSERT INTO UPPER CASE.
E. UPDATE THE DEPT TABLE FOR LIMIT AND UPDATE THE LIMIT FOR DEPTNO
= 2 AND ALSO CHECK THAT LIMIT UPDATED SHOULD BE GREATER THAN ORIGINAL LIMIT.
F.WRITE A INSTEAD OF TRIGGER THAT DELETE ROWS IN EMP_DEPT TABLE THAT MATHCHES
THE ROW ENTERED.
FACULTY OF COMPUTER SCIENCE
Master of Computer Application (Sem-III)
In Effect from Academic Year 2017-18
D. WRITE A TRIGGER FOR INSERT OR UPDATE TO CHECK THAT EMP NAME STARTS
WITH 'M%' FOR MR AND MRS.