Dbms Lab Manual
Dbms Lab Manual
For
(R22 Regulations)
1. Engineering knowledge: Apply the knowledge of mathematics, science, engineering fundamentals, and
an engineering specialization to the solution of complex engineering problems.
2. Problem analysis: Identify, formulate, review research literature, and analyze complex engineering
problems reaching substantiated conclusions using first principles of mathematics, natural sciences, and
engineering sciences.
3. Design/development of solutions: Design solutions for complex engineering problems and design system
components or processes that meet the specified needs with appropriate consideration for the public health
and safety, and the cultural, societal, and environmental considerations.
4. Conduct investigations of complex problems: Use research-based knowledge and research methods
including design of experiments, analysis and interpretation of data, and synthesis of the information to
provide valid conclusions.
5. Modern tool usage: Create, select, and apply appropriate techniques, resources, and modern engineering
and IT tools including prediction and modeling to complex engineering activities with an understanding of
the limitations.
6. The engineer and society: Apply reasoning informed by the contextual knowledge to assess societal,
health, safety, legal and cultural issues and the consequent responsibilities relevant to the professional
engineering practice.
7. Environment and sustainability: Understand the impact of the professional engineering solutions in
societal and environmental contexts, and demonstrate the knowledge of, and need for sustainable
development.
8. Ethics: Apply ethical principles and commit to professional ethics and responsibilities and norms of the
engineering practice.
9. Individual and team work: Function effectively as an individual, and as a member or leader in diverse
teams, and in multidisciplinary settings.
10. Communication: Communicate effectively on complex engineering activities with the engineering
community and with society at large, such as, being able to comprehend and write effective reports and
design documentation, make effective presentations, and give and receive clear instructions.
11. Project management and finance: Demonstrate knowledge and understanding of the engineering and
management principles and apply these to one’s own work, as a member and leader in a team, to manage
projects and in multidisciplinary environments.
12. Life-long learning: Recognize the need for, and have the preparation and ability to engage in
independent and life-long learning in the broadest context of technological change.
COURSE STRUCTURE
(REGULATION:R22)
For The Four Year Under Graduate Programme
Bachelor of Technology (B.Tech)
With effect from the Academic Year 2023-24
DEPARTMENT OF
COMPUTER SCIENCE AND ENGINEERING
(DATA SCIENCE)
DATABASE MANAGEMENT SYSTEMS LAB
B.Tech. II Year II Sem. LT P C
Course Objectives:
Introduce ER data model, database design and normalization
Learn SQL basics for data definition and data manipulation
Course Outcomes:
● Design database schema for a given application and apply normalization
● Acquire skills in using SQL commands for data definition and data manipulation.
● Develop solutions for database applications using procedures, cursors and triggers
List of Experiments:
1. Concept design with E-R Model
2. Relational Model
3. Normalization
4. Practicing DDL commands
5. Practicing DML commands
6. A. Querying (using ANY, ALL, UNION, INTERSECT, JOIN, Constraints etc.)
B. Nested, Correlated subqueries
7. Queries using Aggregate functions, GROUP BY, HAVING and Creation and dropping of Views.
8. Triggers (Creation of insert trigger, delete trigger, update trigger)
9. Procedures
10. Usage of Cursors
TEXT BOOKS:
1. Database Management Systems, Raghurama Krishnan, Johannes Gehrke, Tata Mc Graw Hill,3rd
Edition
2. Database System Concepts, Silberschatz, Korth, McGraw Hill, V edition.
REFERENCE BOOKS:
1. Database Systems design, Implementation, and Management, Peter Rob & Carlos Coronel 7th
Edition.
2. Fundamentals of Database Systems, Elmasri Navrate, Pearson Education
3. Introduction to Database Systems, C.J. Date, Pearson Education
4. Oracle for Professionals, The X Team, S. Shah and V. Shah, SPD.
5. Database Systems Using Oracle: A Simplified guide to SQL and PL/SQL, Shah, PHI.
6. Fundamentals of Database Management Systems, M. L. Gillenson, Wiley Student Edition
PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12
CO1 3 3 3 3 3 - 2 3 3 - - 3
CO2 3 3 3 2 2 2 - 3 3 - - 3
CO3 3 3 3 3 3 - - 3 3 - - 3
CO4 3 3 3 3 3 - - 3 3 - - 3
CO5 3 3 3 - 3 - - 3 3 - - 3
AVG 3 3 3 3 3 2 2 3 3 2 2 3
CO - PSO MAPPING:
PSO1 PSO2
CO1 - 2
CO2 - 1
CO3 - 1
CO4 - 2
CO5 - 1
AVG 0 2
Database:
“A Collection of data files (or) Collection of interrelated data (or) an individual enterprise (or) A
Collection of related files (Containing records) into different groups is known as Database”
Database System:
“It is a Collection of programs that are used to store the data, manipulate the data & retrieve the
information”
Advantages of DBMS:
Reduction of Redundancies
Data independence & efficient Access
Data integrity
Data Security
Reduced Application Development
Conflict Resolution
Data Administration
Concurrent Access
Crash Recovery
Disadvantages of DBMS:
Conversion costs
Installation & Management Cost
New Specialized Personnel
Need for Explicit Backup & Recovery
Security Breaches
Objective:
This lab enables the students to practice the concepts learnt in the subject DBMS by
developing a database for an example company named “Roadway Travels” whose description is
as follows: The student is expected to practice the designing, developing and querying a database
in the context of example database “Roadway Travel”. Students are expected to use “Mysql”
database.
Roadways Travels:
“Roadway travels” is in business since 1997 with several buses connecting different places
in India .Its main office is located in Hyderabad.
Reservations:
Reservations are directly handled by booking office. Reservation can be made 60 days in
advance in either cash or credit .In Case the ticket is not available, a wait listed ticket is issued to
the customer. This ticket is confirmed against the cancellation.
Entity set: It is a collection of all entities of particular entity type in the database.
Extension of entity type: The collections of entities of a particular entity type are grouped
together into an entity set.
Attribute: It is a particular property, which describes the entity.(or) Each entity & relationship
has a property called Attributes.
2. Ellipse (Attributes)
Super Key:
A Super Key of an entity set is a set of one (or) more attributes whose values uniquely
determine each entity.
Candidate Key:
A Candidate Key of an entity set is a minimal super key.
For example: 1) Customer_Id is Candidate Key of Customer
2) Account_ Number is Candidate Key of Account
Primary Key:
Although several Candidate keys may exist, one of the Candidate keys is selected to be the
Primary Key.
Partial Key:
It is a set of attributes that can uniquely identify weak entities and that are related to same
owner entity. It is sometime called as Discriminator.
Example: Entities:
1. Bus
2. Ticket
3. Passenger
Primary key Attributes:
1. Ticket Id (Ticket Entity)
2. Passport Id (Passenger Entity)
Bus Attributes:
BusNo, Dept_time, Source, Destination, WeekDay
Ticket Attributes:
Ticket_No, Journey_Date, Source, Destination, Age, Arrival Time, Depature Time, SEX
Passenger Attributes:
Name, PNO_NO, Ticket_No, PPNO, SEX, Age
Reservation Attributes:
No_of_Seats, PNR_NO, Status, Journey_Date, Address, Contact_No
Cancellation Attributes:
No_of_Seats, PNR_NO, Waiting List, Status, Journey_Date, Address, Contact_No
Readin
g
PNR_N
O
Relate the entities appropriately. Apply cardinalities for each relationship. Identify
Strong entities and Weak entities (if any). Indicate the type of relationships (total/Partial).
Try to incorporate generalization, Aggregation, Specialization etc. wherever required.
Bus NO Source
Bus Destinatio
n
Departure Time
Relationship:-
It is defined as an association among several entities. A relationship can be one-to-one, one-
to-many (or) many-to-many.
A Collection of similar relationships is called a relationship set and is denoted by a Rhombus.
Strong Entity: It is the one that does not depend on other entities.
Weak Entity: It is the one that depends on other entities for existence.
Specialization: All the entities within an entity set do not share all the attributes.
BUS:
Dept_tim Source
e BUS Destination
BusN
o
WeekDay
NAM Passenger
E PPNO
Age SEX
RESERVATION:
PNR_NO
Status
No_of_Seat
s Reservation Journey_Date
Contact_No ADDRESS
Cancellation
Status
No_of_Seat Cancellation
s Journey_Dat
e
Contact_No ADDRESS
TICKET_No Journey_Dat
e
Source
SEX TICKET
Destination
Age
DEPATURE
TIME Arrival Time
WEEK -3:
RELATIONAL MODEL:
Relationship:-
It is defined as an association among several entities. A relationship can be one-to-one, one-
to-many (or) many-to-many.
A Collection of similar relationships is called a relationship set and is denoted by a Rhombus.
Unary Relationship---Where the association is within a single entity
Binary Relationship---A relationship that associates two entities
Ternary Relationship---A relationship that association three entities
Quaternary Relationship—A relationship that associates with four entities
Attribute: It is a particular property, which describes the entity. (or) Each entity & relationship
has a property called Attributes.
1) Simple Attribute -- These attributes are also called as atomic attribute. These
cannot be subdivided further.
2) Composite Attributes -- An attribute which can be further divided into smaller
components are called Composite Attribute.
3) Single-Valued Attributes -- Certain Attribute take only a single value in all
instances.
4) Multi-Valued Attributes -- Attributes that can have more than one value at a
time for an instance.
5) Stored & Derived Attributes -- Some attributes need not be stored but can be
derived from available other attributes.
PASSENGER:
SQL> CREATE TABLE Passenger(PNR_No NUMERIC (9) primary key, Ticket_No
Numeric(9),Name varchar (15),Age number(4),Sex Char(10),PPNO varchar (15),Category
varchar (8));
Table created.
SQL> insert into Passenger values(1000,01,'Anitha',35,'F',10,’A/C’);
1 row created.
SQL> insert into Passenger values(2000,02,'Haritha',30,'F',20,’NONA/C’) ;
1 row created.
SQL> insert into Passenger values(3000,03,'Srilatha',22,'F',30, ’A/C’) ;
1 row created.
SQL> insert into Passenger values(4000,04,'Chaitanya',25,'M',40, ’A/C’) ;
1 row created.
SQL> insert into Passenger values(5000,05,'Saketh',28,'M',50, ’NONA/C’) ;
1 row created.
SQL> insert into Passenger values(6000,06,'Anirudh',27,'M',60, ’NONA/C’);
1 row created.
SQl> Select * from Passenger;
TICKET:
SQL> CREATE TABLE Ticket(Ticket_No NUMERIC(9) Primary Key,Journey_date Date,Age
NUMERIC(4),Sex varchar(10),Source Varchar(10),Arrival_time varchar(6),Destination
Varchar(10),Dep_time varchar(6));
Table created.
SQL> insert into Ticket values(1,’01-jan-2010’,35,'F','Hyderabad',9,'Karimnagar',23);
1 row created.
SQL> insert into Ticket values(2,’02-jan-2010’,30,'F','Delhi',5,'Mumbai',18);
1 row created.
SQL> insert into Ticket values(3,’03-jan-2010’,22,'F','Chennai',6,'Srinagar',16);
1 row created.
SQL> insert into Ticket values(4,’04-jan-2010’,25,'M','Bangalore',8,'Hyderabad',14);
1 row created.
SQL> insert into Ticket values(5,’05-jan-2010’,28,'M','Karimnagar',5,'Warangal',13);
1 row created.
SQL> Select * from Ticket;
Ticket_No Journey_date Age Sex Source Arrival_time Destination Dep_Time
------------- ---------------- ------ ------ ----------- ----------------- -------------- --------------
1 01-jan-2010 35 F Hyderabad 9 Karimnagar 23
2 02-jan-2010 30 F Delhi 5 Mumbai 18
3 03-jan-2010 22 F Chennai 6 Srinagar 16
4 04-jan-2010 25 M Bangalore 8 Hyderabad 14
5 05-jan-2010 28 M Karimnagar 5 Warangal 13
RESERVATION:
SQL> CREATE TABLE Reserve(PNR_No NUMERIC(9), foreign key(PNR_NO) references
passenger(PNR_NO),Journey_date date,No_of_seats number(8),Address
Varchar(40),Contact_No NUMERIC(10),Status Char(2));
Table Created.
SQL> insert into reserve values(1000,'1-feb-2010’,5,'Ramanthpur',0123456789,'Y');
1 row created.
SQL> insert into reserve values(2000,’2-feb-2010’,2,'KPHB',1234567890,'Y');
1 row created.
CANCELLATION:
SQL> CREATE TABLE Cancellation(PNR_No NUMERIC(9), foreign key(PNR_NO)
references passenger(PNR_NO),Journey_date date,No_of_seats NUMERIC(8),
Address Varchar(40),Contact_No NUMERIC(10),Status char(2));
Table Created.
SQL> insert into cancellation values(1000,'1-Jan-2010',5,'Ramanthpur',0123456789,'N');
1 row created.
SQL> insert into cancellation values(2000,'2-feb-2010',5,'KPHB',1234567890,'N');
1 row created.
SQL> insert into cancellation values(3000,'3-feb-2010',4,'Dilsukhnagar',1234567809,'N');
1 row created.
SQL> insert into cancellation values(4000,'4-Apr-2010',2,'tarnaka',1234123412,'N');
1 row created.
SQL> insert into cancellation values(5000,'5-May-2010',6,'DDCOLONY',1234512345,'N');
1 row created.
SQL> Select * from Cancellation;
PNR_No Journey_date No_of_seats Address Contact_No Status
1000 1-jan-2010 5 Ramanthpur 0123456789 Y
2000 2-feb-2010 5 KPHB 1234567890 Y
3000 3-feb-2010 4 Dilsukhnagar 1234567809 Y
4000 4-Apr-2010 2 Tarnaka 1234123412 Y
5000 5-May-2010 6 DDCOLONY 1234512345 Y
Normal forms: The process of normalization is based on the concept of normal forms, Each &
every normal form has its own set of properties & Constraints. A table / relation is said to be in
normal form if it satisfies all the properties of that normal form.
Passenger
1 NF : The domain of attribute must include only atomic (simple, indivisible) values.
For the above table in the First normalization we can remove the multiple valued attribute
Ticket_id and place it in another table along with the primary key of passenger.
Passenger
Passport ID Ticket_id
2 NF: A relation schema R is in 2NF if it is in 1NF and every non-prime attribute A in R is fully
functionally dependent on primary key.
3 NF: A relation schema R is in 3NF if it is in 2NF and for every FD X A either of the
following is true
X is a Super-key of R.
A is a prime attribute of R.
In other words, if every non prime attribute is non-transitively dependent on primary key.
4 NF: A relation schema R is said to be in 4NF if for every multivalued dependency X Y that
holds over R, one of following is true
5 NF: A Relation schema R is said to be 5NF if for every join dependency {R1, R2... Rn} that
holds R, one the following is true
Installation of MySql In this week you will learn Creating Databases, How to create tables,
altering the database, dropping tables & databases if not required. You will also try
truncate, rename commands etc.
Create table passenger (passport id Integer primary key, name char(50) null, age integer,
Sex char);
4. Modifying existing columns: By using modify, we can change the datatype of a particular field
Syntax: Alter table <tablename> modify(<col><newdatatype>(<newsize>));
Ex: alter table emp modify(ename varchar2(15));
5. Renaming the tables: It is used to change the table name which was already created.
Syntax: Rename <oldtable> to <new table>;
Ex: rename emp to emp1;
6. Truncating the tables: This DDL will support to delete all the rows of a table for permanent
Syntax: Truncate table <tablename>;
Ex: trunc table emp1;
7. Destroying tables. Drop command is used to destroy the existing table (or) a view.
Syntax: Drop table <tablename>;
Ex: drop table emp;
BUS:
SQL> CREATE TABLE BUS (BusNo varchar (10) primary key, Source varchar (15),
Destination varchar (15));
Table Created.
SQL> desc Bus
Name Null? Type
Table Dropped.
Table Renamed.
Table Truncated.
PASSENGER:
Table Renamed.
Table Truncated.
TICKET:
Table Dropped.
Table Renamed.
Table Truncated.
RESERVATION:
Table Created.
Table Dropped.
Table Renamed.
Table Truncated.
CANCELLATION:
Table Dropped.
Table Renamed.
Table Truncated.
1. Inserting Data into Tables: - once a table is created the most natural thing to do is load
this table with data to be manipulated later.
Syntax:
insert into <tablename> (<col1>,<col2>) values(<exp>,<exp>);
2. Delete operations.
BUS:
SQL> CREATE TABLE BUS (BusNo varchar (10) primary key, Source varchar (15),
Destination varchar (15), Weekday varchar (10));
Table Created.
1 row updated.
5 rows updated.
1 row deleted.
PASSENGER:
Table created.
1 row updated.
6 rows updated.
1 row deleted.
5 rows updated.
1 row deleted.
RESERVATION:
Table Created.
5 rows updated.
CANCELLATION:
5 rows updated.
Week 7: Querying:
In this week you are going to practice queries (along with sub queries) using ANY, All, In,
Exists, Not Exists, Union, Intersect, Constraints etc
Query: A query with respect to DBMS relates to user commands that are used to interact with a
data base. The query language can be classified into data definition language and data
manipulation language.
Sub Query: Sub queries, or nested queries, are used to bring back a set of rows to be used by the
parent query. Depending on how the sub query is written, it can be executed once for the parent
query or it can be executed once for each row returned by the parent query. If the sub query is
executed for each row of the parent, this is called a correlated sub query.
Correlated sub query: A correlated sub query can be easily identified if it contains any
references to the parent sub query columns in its WHERE clause. Columns from the sub query
cannot be referenced anywhere else in the parent query. The following example demonstrates a
non-correlated sub query.
E.g. Select * From CUST Where '10/03/1990' IN (Select ODATE from ORDER Where
CUST.CNUM = ORDER.CNUM)
Any:
This operator will make inner query to return multiple rows, where from those rows, least value
is extracted & then sends that value for comparison at the condition of outer query.
This operator also makes inner query to return multiple rows of which it selects the biggest value
& sends that value for comparison at the condition of outer query.
Syntax: select <select list> from <TN><alias name1>where<condition (op) All > (select<select
list>) from <TN><alias name2> where <conditionlist>
IN:
Exists:
This operator is used to co-related queries that returns those rows of outer query for which the
inner query condition get satisfied.
Not Exists:
This operator will return true for that condition which doesn’t get satisfy at inner query. If the
condition becomes true it becomes false at the Boolean value & those rows will be avoided at
retrieval.
Syntax: select <select-list> from <TN><alias name> where Not Exists(select * from<TN><alias
name> where <condition>
Union:
It joins the rows returned by 2 (or) more queries, by avoiding duplicates & arranging the rows in
ascending order.
SQL> select source from bus union select source from ticket;
Intersect:
This operator will extract the common values which are found in the rows returned by 2 (or)
more queries.
SQL> select source from bus intersect select source from ticket;
PNR_NO
------
1000
2000
3000
4000
5000
2) Display all the names of male passengers
NAME
TICKET_NO NAME
---------- ---------------
1 Anitha
2 haritha
3 Srilatha
4 chaitanya
5 saketh
4) Display the source and destination having journey time more than 10 hours.
5) Find the ticket numbers of the passengers whose name start with ‘A’ and ends with ‘H’.
SQL> select ticket no from passenger where name like 'A % h';
TICKET_NO
----------
6
6) Find the age of passengers whose age is between 30 and 45.
SQL> select name from passenger where age between 30 AND 45;
NAME
---------------
Anitha
Haritha
NAME
---------------
Anitha
Anirudh
10) Display the details of Passengers who are travelling either in AC or NONAC.
You are going to practice queries using Aggregate functions(Count, Sum, Avg, Max & Min)
Group By, Having & Creation & dropping of views.
Aggregate Operator:
SQL supports 5 aggregate operators, which can be applied on any column of a relation.
1. Count
1) Count: It is used to count the number of unique columns (or) values in a given column.
Syntax: select count (*) from <TN>(alias name);
3)Average(Avg): It retrieves the average of all (unique) values in the given column.
Syntax : select Avg (column name) from <TN> <alias name>where <where condition>
Syntax: select select-list from from-list where condition Groupby Group list Having group-
qualification;
View:
The view is a table whose rows are not explicity stored in the database, but are computed as
needed from the view definition.
Pnr_no
----------
1000
2000
3000
4000
5000
6000
3. Display the number of days in a week on which the 9w01 bus is available
4. Find number of tickets booked for each pnr_no using group by clause. Hint: Use Group
By on pnr_no
Pnr_no
----------
1000
2000
3000
4000
5000
6000
6. Find the number of tickets booked in each class where the number of seats is
greater than 1. Hint: Use Group by, Where & Having Clauses
8. Write a query to count the number of tickets for the buses, which traveled after the
date ‘14/3/2009’ Hint: Use Having Clauses
In this week you are going to work on triggers. Creation of insert trigger, delete trigger,
update trigger. Practice triggers using the above database
Triggers:
Example:
A trigger called check_sal which runs every time a new employee is getting inserted to enforce
some rules on what should be the minimum salary.
Elements in a Trigger:
Trigger timing
o For table: BEFORE, AFTER
o For view: INSTEAD OF
Trigger event: INSERT, UPDATE, OR DELETE
Table name: On table, view
Trigger Type: Row or statement
When clause: Restricting condition
Trigger body: PL/SQL block
Before triggers:
“Before triggers” execute the trigger body before the triggering DML event on a table. These are
frequently used to determine whether that triggering statement should be allowed to complete. This
After triggers
“After triggers” are used when the triggering statement is to be completed before the triggering
action and to perform a different action on the same triggering statement if a BEFORE trigger is
already present.
Instead of Triggers
“Instead of Triggers” are used to provide a transparent way of modifying views that cannot be
modified directly through SQL DML statements because the view is not inherently modifiable.
You can write INSERT, UPDATE, and DELETE statements against the view. The INSTEAD OF
trigger works invisibly in the background performing the action coded in the trigger body directly
on the underlying tables.
Trigger Components:
o Statement: The trigger body executes once for the triggering event. This is the default. A
statement trigger fires once, even if no rows are affected at all.
o Row: The trigger body executes once for each row affected by the triggering event. A row
trigger is not executed if the triggering event affects no rows.
Trigger Body:
The trigger body is a PL/SQL block or a call to a procedure.
Syntax:
In this session you are going to learn creation of stored procedure, execution of procedure
& modification of procedure. Practice procedures using the above database.
Stored Procedure:
A stored procedure or in simple a proc is a named PL/SQL block which performs one or more
specific task. This is similar to a procedure in other programming languages. A procedure has a
header and a body. The header consists of the name of the procedure and the parameters or
variables passed to the procedure. The body consists or declaration section, execution section
and exception section similar to a general PL/SQL Block. A procedure is similar to an
anonymous PL/SQL Block but it is named for repeated usage.
IS - marks the beginning of the body of the procedure and is similar to DECLARE in anonymous
PL/SQL Blocks. The code between IS and BEGIN forms the Declaration section.
The syntax within the brackets [ ] indicate they are optional. By using CREATE OR REPLACE
together the procedure is created if no other procedure with the same name exists or the existing
procedure is replaced with the current code.
The below example creates a procedure ‘employer_details’ which gives the details of the
employee.
procedure_name;
NOTE: In the examples given above, we are using backward slash ‘/’ at the end of the program.
This indicates the oracle engine that the PL/SQL program has ended and it can begin processing
the statements.
In this week you need to do the following: Declare a cursor that defines a result set.
Open the cursor to establish the result set. Fetch the data into local variables as needed
from the cursor, one row at a time. Close the cursor when done.
Cursors:
Every SQL statement executed by the Oracle server has an individual cursor associated with it and
are called implicit cursors.
There are two types of cursors.
Implicit cursors: Declared for all DML and PL/SQL SELECT statements.
Explicit cursors: Declared and names by the programmer.
Explicit Cursors:
o Individually process each row returned by a multiple row select statement.
o Can process beyond the first row returned by the query, row by row.
o Keep track of which row is currently being processed.
o Allow the programmer to manually control explicit cursors in the PL/QL block.
o Declare the cursor by naming it and defining the structure of the query to be performed.
Within it.
o Open the cursor: The OPEN statement executes the query and binds the variables that are
referenced. Rows identified by the query are called the active set and are now available for
fetching.
o Fetch data from the cursor: After each fetch, you test the cursor for any existing row. If
there are no more rows to process, then you must close the cursor.
o Close the cursor: The CLOSE statement releases the active set of rows. It is now possible
to reopen the cursor to establish a fresh active set
Syntax:
Declaring a cursor:
CURSOR cursor_name IS
Select_statement;
Opening a cursor:
OPEN cursor_name;
Closing a cursor:
Close cursor_name;
Example:
Set SERVEROUTPUT ON
DECLARE
V_empno employees.employee_id%TYPE;
V_ename employees.last_name%TYPE;
CURSOR emp_cursor IS
SELECT employee_id, last_name
FROM employees;
BEGIN
OPEN emp_cursor;
Cursors can be passed parameters. Cursors also have FOR UPDATE option which allows more
fine grained control of locking at a table level. WHERE CURRENT OF can be used to apply the
update or delete operation to current row in the cursor.
Beyond Syllabus
1. Database connectivity in Mysql
<?php
$servername = "localhost";
$username = "username";
$password = "password";
// Create connection
$conn = mysqli_connect($servername, $username, $password);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
echo "Connected successfully";
?>
DECLARE
x int:=&x; /*taking value at run time*/
BEGIN
IF y=0 then
raise exp1;
ELSE
div_r:= x / y;
dbms_output.put_line('the result is '||div_r);
END IF;
EXCEPTION
WHEN exp1 THEN
dbms_output.put_line('Error');
dbms_output.put_line('division by zero not allowed');
END;