2015 Summer Model Answer Paper
2015 Summer Model Answer Paper
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER-15 EXAMINATION
Model Answer
Page 1 of 40
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER-15 EXAMINATION
Model Answer
Ans:
The symbols used in E-R diagram are:
Page 2 of 40
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER-15 EXAMINATION
Model Answer
Ans:
Primary key: Within a relation there is always one attribute which has values that are
unique in a relation and thus can be used to identify tuple of that relation. Such a unique
identifier is called the primary key.
E.g. In the Student(Rollno,name,class,address) relation Rollno is the primary key.
Ans:
List of DML commands:
1. Select
2. Insert
3. Update
4. Delete
Page 3 of 40
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER-15 EXAMINATION
Model Answer
7) What is cursor?
(Explanation of cursor-2Marks)
Ans:
Cursor:
The Oracle Engine uses a work area for its internal processing in order to execute an SQL
statement. This work area is private to SQL‟s operations and is called a Cursor.
OR
A cursor is a temporary work area created in the system memory when a SQL statement is
executed.
Ans:
A piece of data in a database table that cannot be broken down any further called atomic
value.
OR
The value of each attribute containing only a single value from that attribute domain is
called atomic value.
Page 4 of 40
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER-15 EXAMINATION
Model Answer
Data integrity:
Data integrity refers to maintaining and assuring the accuracy and consistency
of data over its entire life-cycle.
Data integrity is usually imposed during the database design phase through the
use of standard procedures and rules.
Data integrity can be maintained through the use of various error checking methods
and validation procedures.
e.g The balance of certain type of bank account may never fall below a prescribed amount(
Rs.5000).
We can handle this through program code and declaring integrity constraint along with
definition.
Page 5 of 40
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER-15 EXAMINATION
Model Answer
Revoke: This command is used to withdraw the privileges that has been granted to a user.
Syntax: Revoke <object privileges>on<object name>from <username> ;
Example: Revoke select, update on empfrom user1;
Ans:
The Syntax for creating a trigger is:
CREATE [OR REPLACE ] TRIGGER trigger_name
{BEFORE | AFTER | INSTEAD OF }
{INSERT [OR] | UPDATE [OR] | DELETE}
ON table_name
[FOR EACH ROW/For Each statement]
WHEN (condition)
BEGIN
--- sql statements
END;
(OR)
Page 6 of 40
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER-15 EXAMINATION
Model Answer
Example
CREATE or REPLACE TRIGGER After_Update_Row_product
AFTER
insert On product
FOR EACH ROW
BEGIN
INSERT INTO product_check Values('After update, Row level',sysdate);
END;
Advantages of triggers:
1. Triggers provide an alternative way to check the integrity of data.
2. Can catch errors in business logic in the database layer.
3. SQL triggers provide an alternative way to run scheduled tasks.
4. Triggers are very useful to audit the changes of data in tables.
Page 7 of 40
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER-15 EXAMINATION
Model Answer
1 It does not have sufficient attribute to It has its own primary key.
form a primary key on its own.
2 The relationship between one strong The relationship between two strong entity set is
and a weak entity set is represented by represented by a diamond symbol
a double diamond symbol.(known as
identifying relationship)
3 The Member of weak entity set is The member of strong entity set is called as
called as subordinate entity set. dominant entity set.
5 The line connecting weak entity set The line connecting strong entity set with the
with the identifying relationship is relationship is single.
double.
6
Page 8 of 40
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER-15 EXAMINATION
Model Answer
Functional Dependency:
A functional dependency occurs when one attribute in a relation uniquely determine
another attribute.
OR
Transitive dependency:
A transitive dependency can occur only in a relation that has three or more attributes. Let
A, B, and C designates three distinct attributes (or distinct collections of attributes) in the
relation. Suppose all three of the following conditions hold:
1. A → B
2. It is not the case that B → A
3. B → C
Then the functional dependency A → C is a transitive dependency.
OR
If we have a primary key A and a non-key domain B and C, where C is more dependent on
B than A and B is directly dependent on A, then C can be considered transitively
dependant on A.
Page 9 of 40
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER-15 EXAMINATION
Model Answer
Example:
Consider the relation SUPPLIER (SNO, SNAME, CITY, STATUS).
In this dependency SNAME is functionally dependent on SNO and STATUS is dependent
on CITY with CITY dependent on SNO, which shows a transitive dependency i.e.
STATUS is depending on SNO(via CITY).
OR
Page 10 of 40
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER-15 EXAMINATION
Model Answer
Example:
Consider table “persons”
Last_Name First_name Address City
Page 11 of 40
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER-15 EXAMINATION
Model Answer
Ans:
Simple index: An index created on single column of a table is called a Simple Index.
Syntax: Create index on <tablename><column name>;
E.g.: Create index idx on employee (empno);
Composite Index:An Index that contain two or more columns from the same table is
called as Composite Index.
Syntax: Create index on <tablename><column name1, Column name 2>;
E.g.: Create index idx on employee (ename, empno);
Page 12 of 40
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER-15 EXAMINATION
Model Answer
Data Warehousing:-
A data warehouse is a repository of information gathered from multiple sources, stored
under a unified schema, at a single site. Once gathered, data are stored for long time,
permitting access to historical data.
Data warehouses provide the user a single consolidated interface to data, making
decision-support queries easier to write.
Moreover, by accessing information for decision support from a data warehouse, the
decision makers ensures that online transaction-processing systems are not affected by
decision support workload.
Page 13 of 40
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER-15 EXAMINATION
Model Answer
Page 14 of 40
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER-15 EXAMINATION
Model Answer
Advantages of PL/SQL :
1. PL/SQL is that development tool which not only supports SQL data manipulations but
also provides facilities of conditional checking and looping.
2. PL/SQL sends an entire block of SQL statement to the ORACLE engine all in one go.
3. PL/SQL also permits dealing with errors as required, and facilitates displaying user-
friendly messages, when errors are encountered.
4. PL/SQL allows declaration and use of variables in blocks of code. These variables can be
used to store intermediate results of a query for later processing, or calculate values and
insert them into an ORACLE table later. PL/SQL variables can be used anywhere, either
in SQL statements or in PL/SQL blocks.
5. Applications written in PL/SQL are portable to any computer hardware and operating
system, where Oracle is operational.
Page 15 of 40
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER-15 EXAMINATION
Model Answer
1. At creation time (Assuming Dept is already created with deptno as primary key)
Create table Emp ( empid number(4), empname varchar(20), deptno number(3)
constraint fk1 references Dept(deptno) , salary number(10,2));
2. After creation :
Alter table Emp add constraint fk1 foreign key (deptno) references dept(deptno);
On delete cascade :
When a relation is created between two tables, it is permissible to delete records in child
table , but a vice–versa operation is not allowed. i.e. deleting records from parent table
when it is referenced from some other table is not allowed.
On delete cascade clause allows automatic deletion of child records when parent record is
deleted.
Eg :
Alter table Emp add constraint foreign key emp(deptno) references dept(deptno) on delete
cascade;
Page 16 of 40
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER-15 EXAMINATION
Model Answer
d) What is sequence? What are the various operations with respect to sequences?
(Sequence explanation – 2 Marks, any two operations – 2 Marks)
Ans:
Sequence :
In a table, generally there exists a column which can uniquely identify the record from
a table. For that purpose, that column has to be a primary key which can never contain
duplicate or null value.
There are great chances of errors in manual entry of data, which can be minimized by
creating sequence for automatic entry of certain values which are in sequence.
Sequence creates a series of values which are computer generated and which can be
inserted into a table.
Oracle provides an object called as a Sequence that can generate numeric values. The
value generated can have maximum of 38 digits.
These numbers can be ascending or descending order.
Provide intervals between numbers.
1) Create a sequence :
INCREMENT BY:Specifies the interval between sequence number. It can be any positive
or negative value but not zero. If this clause is omitted the default value is 1.
MINIVALUE: Specifies the sequence minimum value.
NOMINVALUE: Specifies the maximum value of 1 for an ascending sequence and –
(10)^26 for a descending sequence.
MAXVALUE: Specifies the maximum value that a sequence can generate.
Page 17 of 40
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER-15 EXAMINATION
Model Answer
2) Referncing a sequence
Once a sequence is created SQL can be used to view the values held in its cache. To
simply view sequence value use a SELECT sentence as describe below.
SELECT<SequenceName>.NextVal FROM DUAL;
Every time nextval reference a sequence its output is automatically increment from the old
values to the values to the new value ready for use.
INSERT INTO
ADDR_DTLS(ADDR_NO,CODE_NO,ADDR_TYPE,ADDR1,ADDR2,CITY,STATE,PI
NCODE)VALUES(ADDR_SEQ.NextVal,‟B5‟,‟B‟,‟Vertex Plaza,Shop 4,‟,‟Western
Express Highway,Dahisar(East),‟,‟Mumbai‟,‟400078‟);
To reference the current value of a sequence:
SELECT<SequenceName>.CURRVAL FROM DUAL;
3) Altering a sequence
A sequence once created can be altered. This is achieved by using the ALTER
SEQUENCE statement .
SYNTAX:
ALTER SEQUENCE<SequenceName>
[Increment by <IntegerValue> Maximum<IntegerValue>/NOMAXVALUE
MINVALUE<IntegerValue>/NOMINVALUE CYCLE/NOCYCLE
CACHE<IntegerValue>/NOCACHE ORDER/NOORDER]
Change the cache value of the sequence ADDR_SEQ to 30 and interval between two
numbers as 2.
ALTER SEQUENCEADDR_SEQ INCREMENT BY 2 CACHE 30;
Page 18 of 40
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER-15 EXAMINATION
Model Answer
4) Dropping A Sequence
The DROP SEQUENCE command is used to remove the sequence from database.
Syntax:
DROP SEQUENCE<SequenceName>;
Shared Exclusive
It requires the locking and unlocking of the transaction to be done in two phases.
1) Growing phase: In this phase, a transaction may obtain locks, but may not release
locks.
2) Shrinking phase: In this phase, a transaction may release locks, but may not acquire
any new locks.
Page 19 of 40
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER-15 EXAMINATION
Model Answer
DBMS RDBMS
1. Database Management System 1. Relational Database Management
System
2. It is mainly used for storage of 2. It is that environment where data is
data and efficient retrieval. represented in the form of relations,
with enforced
relationships between the tables.
3. Mainly used for single user 3. Generally used in multiuser
system environment.
4. Not all Codd rules are satisfied. 4. All 12 Codd rules are satisfied.
5. Suitable for low volume of data 5. Suitable for large volume of data
6. Security is less. 6. More security measures provided
7. Example : Forxpro, dbaseIII plus 7. Example : Oracle, SQL Server
Page 20 of 40
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER-15 EXAMINATION
Model Answer
Page 21 of 40
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER-15 EXAMINATION
Model Answer
DROP TRUNCATE
1 .It is a DDL Statement which 1.It is DDL statement which deals
deals with the structure of the only with the data from the table.
table along with data.
2. It deletes entire table at once 2.It deletes all records from table at
from the disk. once.
3.Column Structure of table does 3.Empty column structure of the
not remain on the disk. table remains on the disk.
4.Syntax : 4.Syntax :
Page 22 of 40
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER-15 EXAMINATION
Model Answer
Ans:
Schedule : A Schedule is a nothing but the order in which multiple transactions can be
executed.
Conflict serializibility:
The correctness and consistency of transaction schedules can be decided by serializibility
property. The seriazable schedule is that which maintains the same consistency before and
after the execution of a particular schedule. If it doesn‟t , it is called as conflict
serializibility. Serial schedule never shows conflict serializibility, concurrent may show it.
Example :
Consider Transaction T1 : which transfers 50 Rs. From A‟ s account to B‟s account.
And transaction T2 : Displays (A+B)
Initially a has 100 Rs and B has 150 Rs. in their accounts respectively.
The consistency can be checked as after both the transactions are over (A+B) always
should be 250. If not, there is a conflict serializibily.
Page 23 of 40
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER-15 EXAMINATION
Model Answer
T1
READ(A)
A:=A-50
WRITE(A)……A=50 T2
READ(A)……A=50
READ(B)…….B=150
DISPLAY(A+B)………A+B=200…….Conflict Serializibility
READ(B)
B:=B+50
WRITE(B)
Page 24 of 40
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER-15 EXAMINATION
Model Answer
Page 25 of 40
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER-15 EXAMINATION
Model Answer
Ans:
Data Abstraction:
The need for efficiency has led designers to use complex data structures to represent data
in the database. Since many database-systems users are not computer trained, developers
hide the complexity from users through several levels of abstraction, to simplify users‟
interactions with the system:
1. Physical level. The lowest level of abstraction describes how the data are actually
stored. The physical level describes complex low-level data structures in detail.
2. Logical level. The next-higher level of abstraction describes what data are stored in the
database, and what relationships exist among those data. The logical level thus
describes the entire database in terms of a small number of relatively simple structures.
3. View level. The highest level of abstraction describes only part of the entire database.
Many users of the database system do not need all this information; instead, they need
to access only a part of the database. The view level of abstraction provides many
views for the same database.
Page 26 of 40
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER-15 EXAMINATION
Model Answer
Ans:
SQL Join types are as follows:
2) SELF JOIN:
The SQL SELF JOIN is used to join a table to itself, as if the table were two tables,
temporarily renaming at least one table in the SQL statement.
Syntax:
SELECT a.column_name, b.column_name...
FROM table1 a, table1 b
WHERE a.common_filed = b.common_field;
Example:
Select x.stud_name, y.stud_name from stud_infox,stud_info y
Where x.leader= y.stud_id;
Page 27 of 40
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER-15 EXAMINATION
Model Answer
OR
Select column1name,column2name
from
table1name left outer join table2name on
table1name.columnname= table2name.columnname;
Example:
select
last_name,department_name
from
employeese,departments d
on
e.department_id(+) = d.department_id;
OR
select
last_name,department_name
from
employees left outer join departments
on
employees.department_id = departments.department_id;
Page 28 of 40
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER-15 EXAMINATION
Model Answer
Example:
Select last_name,department_name
from
employeese,departments d
on
e.department_id = d.department_id(+);
OR
Select last_name,department_name
from
employees e right outer join departments d
on
e.department_id = d.department_id;
Page 29 of 40
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER-15 EXAMINATION
Model Answer
SQL> Begin
Factorial(5);
End;
Page 30 of 40
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER-15 EXAMINATION
Model Answer
function procedure
1. Syntax: Syntax:
CREATE [OR REPLACE] CREATE OR REPLACE FUNCTION
PROCEDURE proc_name [list function_name (argument IN data type
of parameters] ,…)
IS <Local Declaration section RETURN datatype {IS,AS}
> Variable declaration;
BEGIN Constant declaration;
Execution section BEGIN
EXCEPTION PL/SQL statements;
Exception section EXCEPTION
END; Exception PL/SQL block
END;
2. Return type is must Return type is not must
3. It can return any scalar or table It can directly return only integers
Page 31 of 40
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER-15 EXAMINATION
Model Answer
e) Given:
driver (driver_id, driver_name, age, rating)
bus (bus_id, bus_name, color)
reserves (driver_id, bus_id, date);
Write Relational Algebra Queries for
Ans:
Ans:
Commit:
The COMMIT command is used to save changes invoked by a transaction to the
database.
The COMMIT command saves all transactions to the database since the last COMMIT
or ROLLBACK command.
The syntax for COMMIT command is as follows:
SQL> COMMIT;
Page 32 of 40
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER-15 EXAMINATION
Model Answer
Savepoint:
A SAVEPOINT is a point in a transaction when you can roll the transaction back to a
certain point without rolling back the entire transaction.
The syntax for SAVEPOINT command is as follows:
SAVEPOINT SAVEPOINT_NAME;
e.g. SAVEPOINT SV1;
Rollback:
The ROLLBACK command is used to undo transactions that have not already been
saved to the database.
The ROLLBACK command can only be used to undo transactions since the last
COMMIT or ROLLBACK command was issued.
The syntax for rolling back to a SAVEPOINT is as follows:
ROLLBACK TO SAVEPOINT_NAME;
Ans:
Disadvantages of file processing system
Page 33 of 40
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER-15 EXAMINATION
Model Answer
3. Data isolation
As the data scattered in various files and files may be in different formats, writing new
application programs to retrieve the data is very difficult.
4. Integrity problems
The data values stored in the database must satisfy certain types of consistency
constraints. When new constraints are added, it is difficult to change the programs to
enforce them.
5. Atomicity problems
A computer system, like any other mechanical or electrical device, is subject to failure.
If any failure occurs in the system the transaction which are executing should fully get
executed or should not, so that database remains in consistent state.
6. Concurrent-access anomalies
To improve the performance of the system, multiple transactions must get executed
concurrently. Multiple transactions may be updating the same data concurrently. In
such case the data may result in inconsistent state
7. Security problems
Only authorized person should be able to modify the data. Security should be
maintained at different levels which were not possible in file processing system.
Page 34 of 40
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER-15 EXAMINATION
Model Answer
Ans:
Functional Dependencies:
Roll_No Name
Roll_No Class
Total_Marks Percentage
Percentage Grade
1NF:
1) Student (Roll_No, Name, Class, Total_Marks, Percentage, Grade)
2NF:
1) Student(Roll_No, Name, Class)
2) Marks(Roll_No, Total_Marks, Percentage, Grade)
3NF:
1) Student(Roll_No, Name, Class )
2) Marks(Roll_No, Total_Marks, Percentage)
3) Grade (Percentage, Grade)
Page 35 of 40
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER-15 EXAMINATION
Model Answer
Ans:
To ensure integrity of the data, we require that the database system maintain the
following properties of the transactions (ACID properties):
Atomicity: Either all operations of the transaction are reflected properly in the
database, or none are.
Consistency: Execution of a transaction in isolation (that is, with no other transaction
executing concurrently) preserves the consistency of the database.
Isolation: Even though multiple transactions may execute concurrently, the system
guarantees that, for every pair of transactions Ti and Tj, it appears to Ti that either
Tjfinished execution before Ti started, or Tjstarted execution after Ti finished. Thus,
each transaction is unaware of other transactions executing concurrently in the system.
Durability: After a transaction completes successfully, the changes it has made to the
database persist, even if there are system failures.
Ans:
An attribute can be characterized by the following attribute types:
1. Simple attributes: Attributes which cannot be divided into subparts are known as
Simple attributes. E.gRollNo.
2. Composite attributes:Attributes which can be divided into subparts (that is, other
attributes).
e.g Name can be divided as First_name,Middle_name,Last_name
3. Single-valued attribute: The attributes that hold a single value for a single entity are
single-valued attributes. E.g DOB
4. Multivalued attributes :There may be instances where an attribute has a set of values
for a specific entity. E.gTelephoneNo
5. Derived attributes: The value for this type of attribute can be derived from the values
of other related attributes or entities. E.g Age attribute can be derived from attribute
DOB
6. Null attributes : a NULLvalue is used when an entity does not have a value for an
attribute.
Page 36 of 40
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER-15 EXAMINATION
Model Answer
Ans:
Group by clause
The group by clause can be used in a select statement to collect data across
multiple records and group by one or more columns.
The group by field contains the repetitive records or values like department number
in employee.
The syntax is:
Select col1,col2,….,col n aggregate_function (expression)
From table_name
Where predicates
Group by column_name;
Example: Display average salary of each department
Select avg(sal)
From emp
group by deptno;
Order by clause:
The ORDER BY keyword is used to sort the result-set by one or more columns.
The ORDER BY keyword sorts the records in ascending order by default.
To sort the records in a descending order, you can use the DESC keyword.
Syntax:
SELECT column_name,column_name
FROM table_name
ORDER BY column_name,column_name ASC|DESC;
Example:
1. SELECT * FROM Customers
ORDER BY Country;
2. SELECT * FROM Customers
ORDER BY Country DESC;
Page 37 of 40
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER-15 EXAMINATION
Model Answer
2. Nested If:
• In this, any number of ELSIF clauses can be used with one IF statement.
• Either set of actions of the result of the first IF statement of ELSE statement can
contain further IF statements before specific actions are performed.
• Each nested IF statement must terminate with a corresponding END IF.
• Syntax:
If condition then
Statements
If condition then
Statements
Else
If condition then
Statements
Else condition then
Statements
End if;
End if;
End if;
Page 38 of 40
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER-15 EXAMINATION
Model Answer
3. Case
• Evaluates a list of conditions and returns one of multiple possible result
expressions.
• CASE can be used in any statement or clause that allows a valid expression. For
example, you can use CASE in statements such as SELECT, UPDATE, DELETE
and SET, and in clauses such as select_list, IN, WHERE, ORDER BY, and
HAVING.
• Synatx:
CASE [ expression ]
WHEN condition_1 THEN result_1
WHEN condition_2 THEN result_2
...
WHEN condition_n THEN result_n
ELSE result
END
Iterative Control:
1. Simple Loop
2. While Loop
3. For Loop
4. Simple Loop
LOOP statements let you execute a sequence of statement multiple times.
Place the keyword LOOP before the first statement in the sequence and the
keyword END LOOP after the last statement in the sequence.
Syntax:
Endless loop
LOOP
<loop_body>
END LOOP;
Conditional loop
LOOP
<loop_body>
EXIT WHEN (Condition);
END LOOP;
Page 39 of 40
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER-15 EXAMINATION
Model Answer
The EXIT WHEN statement lets you complete a loop if further processing is impossible
or undesirable.
When the EXIT statement encountered, the condition in the WHEN clause is evaluated.
If the condition is true, the loop completes and control passes to the next statement.
5. While Loop
The WHILE LOOP statement associates a condition with a sequence of statements.
Before each iteration of loop, the condition is evaluated.
If the condition is true, the sequence of statement is executed, then control resumes at the
top of the loop.
If the condition is false or null, the loop is bypassed and control passes to the next
statement.
Syntax:
WHILE <Condition> LOOP
<loop body>
END LOOP;
6. For Loop :
The FOR LOOP statement specifies a range of integers, then execute a sequence of
statements once for each integer in the range.
To reverse the range , “REVERSE” keyword is used.
The syntax is :
FOR i IN 1..N LOOP
<loop_body>
END LOOP;
7. Sequential Control:
Label can be used to give a label or name to the piece of code. And once the name is
given to it, user can call that piece of code with that label whenever and wherever
required in the program .
Syntax for label is as follows:
<<label_name>>
Statements;
The Goto statement is used to transfer the control or to change the sequence of the
instructions.
Syntax for goto statement is as follows:
Goto<<label_name>>
Page 40 of 40