Professional Documents
Culture Documents
1. Creation, altering and dropping of tables and inserting rows into a table (use constraints
while creating tables) examples using SELECT command
2. Queries (along with sub-Queries) using ANY, ALL, IN, EXISTS, NOTEXISTS, UNION,
INTERSET, Constraints
3. Queries using Aggregate functions (COUNT, SUM, AVG, MAX and MIN), GROUP BY,
HAVING and Creation and dropping of Views.
4. Queries using
Conversion functions (to_char, to_number and to_date),
string functions (concatenation, lpad, rpad, ltrim, rtrim, lower, upper, initcap, length,
substr and instr)
date functions (sysdate, next_day, add_months, last_day,months_between, least,
greatest, trunc, round)
5. Creation of simple PL/SQL program which includes declaration section
executable section and exception handling section (example. Student marks can be
selected from the table and printed for those who secured first class and an exception
can be raised if no records were found)
6. Insert data into student table and use commit and rollback and save point in PL/SQL
block
7. Develop a program that include the features NESTED IF, CASE and CASE
expression.
8. The program can be extended using the NULLIF and COALESCE function
9. Program development using while loops, numeric for loops, nested loops using error
handling, built-in exceptions, user defined exceptions
10. Program development using creation of stored functions, invoke functions in SQL
Statements and write complex functions.
11. Develop programs using features parameters in a CURSOR, FOR UPDATE
CURSOR, WHERE CURRENT of clause and CURSOR variables.
12. Develop Programs using BEFORE and AFTER Triggers, Row and Statement Triggers
and INSTEAD OF Triggers
Page 1
Exp 1: Creation, altering and dropping of tables and inserting rows into a table (use
constraints while creating tables) examples using SELECT command
Page 2
Page 3
Page 4
Page 5
Exp :2 Queries (along with sub Queries) using ANY, ALL, IN, EXISTS, NOTEXISTS,
UNION,INTERSET, Constraints
1. Find the names of sailors who have reserved boat number 103.
SELECT S.sname FROM Sailors S, Reserves R
WHERE R.bid=103 AND S.sid = R.sid ;
4. Find the names of sailors who have reserved a red or a green boat.
(SELECT S.sname FROM Sailors S, Reserves R, Boats B
WHERE B.color = 'red' AND B.bid = R.bid AND R.sid = S.sid )
UNION
(SELECT S.sname FROM Sailors S, Reserves R, Boats B
WHERE B.color = 'green' AND B.bid = R.bid AND R.sid = S.sid );
5. Find all sids of sailors who have a rating of 10 or reserved boat 104.
SELECT S.sid FROM Sailors S
WHERE S.rating = 10
UNION
SELECT R.sid FROM Reserves R
WHERE R.bid = 104;
6. Find the names of sailor's who have reserved both a red and a green boat.
(SELECT S.sname FROM Sailors S, Reserves R, Boats B
WHERE B.color = 'red' AND B.bid = R.bid AND R.sid = S.sid )
INTERSECT
(SELECT S.sname FROM Sailors S, Reserves R, Boats B
WHERE B.color = 'green' AND B.bid = R.bid AND R.sid = S.sid );
Page 6
7. Find the snames of all sailor's who have reserved red boats but not green
(SELECT S.sname FROM Sailors S, Reserves R, Boats B
WHERE B.color = 'red' AND B.bid = R.bid AND R.sid = S.sid )
EXCEPT
(SELECT S.sname FROM Sailors S, Reserves R, Boats B
WHERE B.color = 'green' AND B.bid = R.bid AND R.sid = S.sid );
10. Find the names of sailors who have not reserved a red boat.
SELECT S.sname FROM Sailors S
WHERE S.sid NOT IN (SELECT R.sid FROM Reserves R WHERE R. bid IN
(SELECT B.bid FROM Boats B WHERE B.color = 'red'));
11. Find the names of sailors who have reserved boat number 103.
SELECT S.sname FROM Sailors S
WHERE EXISTS (SELECT * FROM Reserves R WHERE R.bid = 103 AND R.sid =
S.sid ) ;
12. Find sailors whose rating is better than some sailor called Horatio.
SELECT S.sid
FROM Sailors S WHERE S.rating > ANY ( SELECT S2.rating
FROM Sailors S2
WHERE S2.sname = ‘Horatio’);
Page 7
Page 8
Exp 3. Queries using Aggregate functions (COUNT, SUM, AVG, MAX and MIN),
GROUP BY, HAVING and Creation and dropping of Views.
(7) Find names of sailors who are older than the oldest sailor with a rating of 10.
SELECT S.sname FROM Sailors S
WHERE S.age >
( SELECT MAX ( S2.age ) FROM Sailors S2 WHERE S2.rating = 10 );
(8) Find the age of the youngest sailor for each rating level.
Page 9
(9) Find the age of the youngest sailor who is eligible to vote (i.e., is at least
18 years old) for each rating level with at least two such sailors.
(10) For each red boat, find the number of reservations for this boat.
Page 10
Exp :4. Queries using Conversion functions (to_char, to_number and to_date), string
functions (Concatenation, lpad, rpad, ltrim, rtrim, lower, upper, initcap, length, substr
and instr), date functions (Sysdate, next_day, add_months, last_day,months_between,
least, greatest, trunc, round)
Numeric Functions:
Page 11
String Functions:
Page 12
Date Functions:
Page 13
Conversion Functions:
Page 14
Exp 5. i) Creation of simple PL/SQL program which includes declaration section
executable section and exception handling section (example. Student marks can be
selected from the table and printed for those who secured first class and an exception
can be raised if no records were found)
Exception Case
Page 15
ii) Insert data into student table and use commit and rollback and save point in PL/SQL
block
Page 16
Exp 6. Develop a program that include the features NESTED IF, case and CASE
expression. The program can be extended using the NULLIF and COALESCE function
NESTED IF
Page 17
CASE & CASE EXPRESSION
NULL IF
COALESCE: this function returns the first non-null values among the parameters
Page 18
Page 19
Exp 7. Program development using while loops, numeric for loops, nested loops using
error handling, built-in exceptions, user defined exceptions
While Loop : The Sum Of Individual Digits Of Given Number
Page 20
Built-In Exceptions
Page 21
Exp 8: Programs development using creation of procedures, passing parameters IN and
OUT of procedures.
Creation of simple procedure
Page 22
Page 23
Exp 9: Program development using creation of stored functions, invoke functions in
SQL Statements and write complex functions.
Page 24
Exp 10: Develop programs using features parameters in a CURSOR, FOR UPDATE
CURSOR, WHERE CURRENT of clause and CURSOR variables.
Implicit cursor
Page 25
Exp 11: Develop Programs using BEFORE and AFTER Triggers, Row and Statement
Triggers and INSTEAD OF Triggers
Page 26
BEFORE and AFTER using Row level triggers
Page 27
INSTEAD OF TRIGGER
Page 28