M.Sc. - I.T.: Adbms
M.Sc. - I.T.: Adbms
M.Sc. - I.T.: Adbms
Semester II
ADBMS
Sr. No. Title Page No
3
Create Temporal Database.
4
Implement Active database using Triggers
5
Create ORDBMS Application
6
Implement and retrieve records from a Spatial Database
7
XML Application
8
Practical No.1
admin (PASSWORD)
Open ORCL1 Database:
connect SYSTEM/admin@orcl1;
Output:
NAME SALARY
-------------------- ----------
anup 10000
chandu 8199
dipesh 2456
raja 9456
sanket 13000
sibi 3000
siddh 6000
sunita 10000
swapnil 2000
vijay 2100
10 rows selected.
Output:
NAME SALARY EMAIL
-------------------- ---------- -------------------
anup 10000 ak@gmail.com
chandu 8199 cc@gmail.com
raja 9456 rk@gmail.com
sanket 13000 sk@gmail.com
siddh 6000 sm@gmail.com
sunita 10000 sy@gmail.com
6 rows selected.
3 ) Find the employee name and Email where employee number is
known
SQL>select name,address from emp where employee_id=1005 union
select e1.name ,e1.address from emp@conorcl1 e1 where
e1.employee_id=1005
Output:
NAME ADDRESS
-------------------- --------------------
sibi dombivli
Practical No.2
Aim:Vertical fragmentation of database.
Output:
Output:
EMPLOYEE_ID FIRST_NAME EMAIL
----------- -------------------- --------------------
1002 vijay 112.vijay@gmail.com
Output:
EMPLOYEE_ID FIRST_NAME EMAIL
----------- -------------------- --------------------
1001 swapnil sj78@gmail.com
4) Find the employee name whose salary is > 200.
SQL>select e1.employee_id,e1.first_name,e2.salary from emp
e1,emp@conorcl2 e2 where e1.employee_id=e2.employee_id
and e2.salary>=200;
Output:
EMPLOYEE_ID FIRST_NAME SALARY
----------- -------------------- ----------
1001 swapnil 200
1002 vijay 250
1003 dipesh 250
1004 sunita 251
1005 hunusukh 500
Practical No.3
Aim:Creating Replica of database.
Question: Create global conceptual schema Emp (Eno , Ename, Address, Email,
Salary) and insert 10 records. Store the replication of Emp into two different
nodes and fire the following queries.
connect SYSTEM/admin@orcl2;
end if;
if updating then
update emp@conorcl1 set ename=:new.ename where eno=:new.eno;
update emp@conorcl2 set ename=:new.ename where eno=:new.eno;
update emp@conorcl1 set address=:new.address where
eno=:new.eno;
update emp@conorcl2 set address=:new.address where
eno=:new.eno;
update emp@conorcl1 set email=:new.email where eno=:new.eno;
update emp@conorcl2 set email=:new.email where eno=:new.eno;
update emp@conorcl1 set salary=:new.salary where eno=:new.eno;
update emp@conorcl2 set salary=:new.salary where eno=:new.eno;
end if;
if deleting then
delete from emp@conorcl1 where eno=:new.eno;
delete from emp@conorcl2 where eno=:new.eno;
end if;
end;
/
Output Queries:
1 row created.
Output:
E_ID ENAME ADDRESS EMAIL
---------- --------------- ------------------------- ---------
----------------
SALARY
----------
101 Vijay Kalwa vijay@gmail.com
10000
Output:
ENO ENAME ADDRESS EMAIL
---------- --------------- ------------------------- ---------
----------------
SALARY
----------
101 Vijay Kalwa vijay@gmail.com
10000
1 row updated
Output:
E_ID ENAME ADDRESS EMAIL SALARY
---------- --------------- -------------------------
101 Vijay Kalwa vijay@gmail.com 20000
Output:
ENO ENAME ADDRESS EMAIL
---------- --------------- ------------------------- ---------
----------------
SALARY
----------
101 Vijay Kalwa vijay@gmail.com
20000
Output:
1 row deleted.
Output:
no rows selected
Output:
no rows selected
Output:
no rows selected
Practical No.4
Aim: implement Temporal Database.
1) Find all the names of a company whose share price is more than
Rs.100 at 11:45 A.M.
2)Find the name of company which has highest shares price at 5.00
P.M.
Queries:
1) Find all the names of a company whose share price is more than
Rs.100 at 11:45 A.M.
select cname from tbl_shares15
where pricepshare>15
and to_char(transtime,'HH12:MI:AM')='11:45:AM'
Output:
cname
--------------------
Tata
2) Find the name of company which has highest shares price
at 5.00 P.M.
select cname from tbl_shares15 where pricepshare in(select
max(pricepshare) from tbl_shares15 where
to_char(transtime,'HH12:MI:AM')='05:30:PM')
Output:
cname
--------------------
Hero Honda
Output:
Queries:
VALIDTIME
SELECT * FROM Employees where empid=10;
Output:
Practical No.5
Aim: Implement Active database using PL/SQL.
Question: Create table emptab (eno, ename, hrs, pno, super_no) and project
(pname, pno, thrs, head_no) where thrs is the total hours and is the derived
attribute. Its value is the sum of all employees working on that project. eno and
pno are primary keys, head_no is foreign key to emp relation. Insert 10 tuples
and write triggers to do the following.
a) Creating a trigger to insert new employee tuple and display the new total
hours from project table.
b) Creating a trigger to change the hrs of existing employee and display the
new total hours from project table.
c) Creating a trigger to change the project of an employee and display the
new total hours from project table.
d) Creating a trigger to delete the project of an employee.
Creating Table emptab:
Queries:
SQL>insert into emptab values(1011,'abc',21,10,1001)
Output:
PNAME PNO THRS HEAD_NO
-------------------- ---------- ---------- ---------
Bank Management 10 331 1001
Hospital Management 20 75 1002
Speech Recognation 30 710 1004
Cyber Cafe 40 520 1003
SQL>UPDATE EMPTAB
SET HRS=100
WHERE ENO=1001;
SQL> SELECT * FROM PROJECT;
Output:
PNAME PNO THRS HEAD_NO
-------------------- ---------- ---------- ----------
Bank Management 10 421 1001
Hospital Management 20 75 1002
Speech Recognation 30 710 1004
Cyber Cafe 40 520 1003
Output:
PNAME PNO THRS HEAD_NO
-------------------- ---------- ---------- ----------
Bank Management 10 421 1001
Hospital Management 20 75 1002
Speech Recognation 30 710 1004
Cyber Cafe 40 520 1003
d)Creating a trigger to delete the project of an employee
Output:
PNAME PNO THRS HEAD_NO
-------------------- ---------- ---------- ----------
Bank Management 10 421 1001
Hospital Management 20 75 1002
Speech Recognation 30 455 1004
Cyber Cafe 40 520 1003
Practical No.6
Solution:
Creating types and tables
SQL>
Create or replace type AddrType1 as object (Pincode number (5), Street char (20),City varchar2(50), state varchar2(40),
no number(4) );
Type created.
SQL>
create or replace type BranchType as object (address AddrType1, phone1 integer,phone2 integer );
Type created.
2/
Type created.
SQL> create or replace type AuthorType as object (name varchar2 (50), addr AddrType1)2 /
Type created.
SQL>
Table created.
SQL>
create or replace type AuthorListType as varray(10) of ref AuthorType
2/
Type created.
SQL>
create or replace type PublisherType as object(name varchar2(50), addr AddrType1,branches BranchTableType)
SQL>/
Type created
SQL>
create table Publishers of PublisherType NESTED TABLE branches STORE as branchtable
SQL> /
Table created.
SQL>
create table books(title varchar2(50), year date, published_by ref PublisherType,authors AuthorListType)
SQL> /
Table created.
1 row created.
SQL>
insert into Authors values('Rabiner', AddrType1(7007,'Singh street', 'mumbai','maharashtra',1006));
1 row created.
SQL>
insert into Authors values('Schiller',AddrType1(7008,'Pali street', 'nasik','maharashtra',1008));
1 row created.
SQL>
1 row created.
SQL>
insert into Authors values('Sangoi',AddrType1(7008,'Dalal street', 'mumbai','maharashtra',1007));
1 row created.
SQL >
1 row created
1 row created
SQL> insert into Authors values('Richard',AddrType1(7002,'Flower street','pune','maharashtra',03));
1 row created.
SQL>
8 rows selected.
1 row created.
SQL>
insert into Publishers values('Tata',AddrType1(7008,'Jewel
street','mumbai','maharashtra',27),BranchTableType(BranchType(AddrType1(1002,'Diamondstreet','nasik',
'maharashtra',1007),456767,7675757)));
1 row created.
SQL>
1 row created.
SQL>
1 row created
inserting values in table books
SQL>
1 row created.
SQL>
insert into books select 'ADBMS','09-jan-1890',ref(pub), AuthorListType(ref(aut)) from Publishers pub,Authors aut
where pub.name='Mcgrew' and aut.name='Sangoi';
1 row created
.SQL>
insert into books
2 rows created.
List all the authors that have the same pin code as their publisher
NAME
Richard
Rabiner
Schiller
Sangoi
SQL>
select * from books b where 1 < (select count (*) from table (b.authors));
no rows selected
List the name of the publisher that has the most branches
SQL>
Select p.name from publishers p, table (p.branches)group by p.name having count(*)> = all (select count(*)from
publishers p, table(p.branches) group by name);
NAME
--------------------------------------------------
Tata
SQL>
select a.name from authors a, books b, table (b.authors) vwhere v.column_value = ref(a) group by a.name having count(*)
= 1;
no rows selected
List all the authors who have published more than one book & Name of authors whohave published books with atleast
two different publishers
SQL>
select a.name from authors a, books b, table (b.authors) vwhere v.column_value = ref(a) group by a.name having count(*)
> 1;
NAME
Richard
Sangoi
List all books (title) where the same author appears more than once on the list of authors (assuming that an integrity
constraint requiring that the name of an author isunique in a list of authors has not been specified)
SQL>
select title from authors a, books b, table (b.authors) vwhere v.column_value = ref(a) group by title having count(*) > 1;
TITLE
ADBMS
IP
Practical No.7
Aim: Implement and retrieve records from a Spatial Database.
A] Spatial Database
Create a spatial database that stores the number, name and location, which
consists of four different areas say abc, pqr, mno and xyz. Fire the following
queries.
1. Find the topological intersection of two geometries.
2. Find whether two geometric figures are equivalent to each other.
3. Find the areas of all direction locations.
4. Find the area of only one location.
5. Find the distance between two geometries.
B] Spatial Database
Create a spatial database that stores the number, name and location, which
consists of different areas within the university campus including the main
gate, the playground, the arts and science college buildings, the lad and print
facility building. Fire the following queries.
12
11 c
10
8 d
7 b
a
6
e
5
4
g
3
f
2
Symbol Area
A Main gate
B Playground
C Science building
D Lab
E Print facility
F Canteen
G Arts building
A] Spatial Database
Create Table cola_markets:
CREATE TABLE cola_markets (
mkt_id NUMBER PRIMARY KEY,
name VARCHAR2(32),
shape MDSYS.SDO_GEOMETRY);
Index Created
Queries:
Output:
SDO_GEOM.SDO_INTERSECTION(C_A.SHAPE,C_C.SHAPE,0.005)(SDO_GTYPE
, SDO_SRID, SDO_PO
---------------------------------------------------------
SDO_GEOMETRY(2003, NULL, NULL, SDO_ELEM_INFO_ARRAY(1, 1003,
1), SDO_ORDINATE_ARR
AY(4, 5, 3, 3, 5, 3, 5, 5, 4, 5))
Output:
NAME SDO_GEOM.SDO_AREA(SHAPE,0.005)
--------------- ---------------------------
abc 24
pqr 16.5
mno 5
xyz 12.5663706
Output:
NAME SDO_GEOM.SDO_AREA(C.SHAPE,0.005)
----------- --------------------------------
xyz 12.5663706
Output:
SDO_GEOM.SDO_DISTANCE(C_B.SHAPE,C_D.SHAPE,0.005)
------------------------------------------------
1.60555128
B] Spatial Database
)
);
Output:
NAME SDO_GEOM.SDO_AREA(SHAPE,0.005)
---------- ------------------------------
a 3
d 6
e 6
f 4
c 11
g 7
b 12.5663706
7 rows selected.
2)Find out the distance of the main gate from all other objects.
SELECT SDO_GEOM.SDO_DISTANCE(c_b.shape, c_d.shape, 0.005)
FROM university_camp c_b, university_camp c_d
WHERE c_b.name = 'a' AND c_d.name = 'b';
Output:
SDO_GEOM.SDO_DISTANCE(C_B.SHAPE,C_D.SHAPE,0.005)
------------------------------------------------
1
SELECT SDO_GEOM.SDO_DISTANCE(c_b.shape, c_d.shape, 0.005)
FROM university_camp c_b, university_camp c_d
WHERE c_b.name = 'a' AND c_d.name = 'c';
Output:
SDO_GEOM.SDO_DISTANCE(C_B.SHAPE,C_D.SHAPE,0.005)
------------------------------------------------
6.32455532
Output:
SDO_GEOM.SDO_DISTANCE(C_B.SHAPE,C_D.SHAPE,0.005)
------------------------------------------------
6
Output:
SDO_GEOM.SDO_DISTANCE(C_B.SHAPE,C_D.SHAPE,0.005)
------------------------------------------------
6
Output:
SDO_GEOM.SDO_DISTANCE(C_B.SHAPE,C_D.SHAPE,0.005)
------------------------------------------------
7.28010989
Output:
SDO_GEOM.SDO_DISTANCE(C_B.SHAPE,C_D.SHAPE,0.005)
------------------------------------------------
2.23606798
Output:
SDO_GEOM.RELATE(C_B.SHAPE,'ANYINTERACT',C_D.SHAPE,0.005)
--------------------------------------------------------------
------
False
SDO_GEOM.SDO_DISTANCE(C_B.SHAPE,C_D.SHAPE,0.005)
---------------------------------------------------------
1.762
Practical No.8
Aim:XML Application
var nodeList =
xmlDoc.getElementsByTagName("PersonList");
if(nodeList.length > 0){
var parentNode = nodeList(0) ;
var personNode =
xmlDoc.createElement("Person");
var nameNode =
xmlDoc.createElement("Name");
var ageNode =
xmlDoc.createElement("Age");
var genderNode =
xmlDoc.createElement("Gender");
var pcodeNode =
xmlDoc.createElement("PostalCode");
var cityNode =
xmlDoc.createElement("City");
nameNode.text = name;
ageNode.text = age;
genderNode.text= gender;
pcodeNode.text = pcode;
cityNode.text = city;
<html><body>
<CENTER><p><FONT face=Verdana><U><b>Add My Friends to
XML</b></U> </FONT> </p></CENTER>
<form action="VerifyPerson.asp" method="post" name="frmPerson"
id="frmPerson">
<table border=0 align=center style="height: 184px"
width="255">
<TBODY>
<TR><TD width="78"><FONT face=Verdana size=2>
<P align=left>Name:</FONT></P></TD><TD
width="154"><INPUT name=Name ><FONT
face=Verdana size=2></FONT></TD>
<TR><TD width="78"><FONT face=Verdana size=2>Age: </FONT>
</TD><TD width="154"><INPUT name=Age ><FONT
face=Verdana size=2></FONT></TD>
<TR><TD width="78"><FONT face=Verdana
size=2>Gender:</FONT></TD><TD width="154">
<SELECT style="WIDTH: 154px" name=Gender>
<OPTION value=Male selected>Male</OPTION>
<OPTION value=Female>Female</OPTION>
</SELECT>
</TD>
<TR><TD width="78"><FONT face=Verdana size=2>Postalcode:
</FONT> </TD><TD width="154"><INPUT name=Postalcode ><FONT
face=Verdana></FONT></TD>
<td width="3">
<P><FONT face=Verdana></FONT></P></TR>
<TR><TD width="78"><FONT face=Verdana size=2>City: </FONT>
</TD><TD width="154"><INPUT name=City ID="Text1"><FONT
face=Verdana></FONT></TD>
<td width="3">
<P><FONT face=Verdana></FONT></P></TR>
<td width="78">
<P><FONT face=Verdana></FONT></P>
<TR>
<TD COLSPAN=2 width="238"><center><INPUT type=submit
value=Submit name=submit>
<INPUT type=reset value=clear form name=reset></center>
</form>
</TABLE><BR><br>
<CENTER><FONT face=Verdana><U><b>My Friend list</b></U>
</FONT> </CENTER><br>
<table border="1" style="border-collapse: collapse; height:
20px" bordercolor=#000000 align=center bgColor=silver
width="417">
var objXMLDoc =
Server.CreateObject("MICROSOFT.FreeThreadedXMLDOM");
objXMLDoc.async = false;
objXMLDoc.load(Server.MapPath("person.xml"));
var
xsl=Server.CreateObject("MICROSOFT.FreeThreadedXMLDOM");
xsl.async = false;
xsl.load(Server.MapPath("person.xsl"));
var xmlQuery="//Person";
var
docHeadlines=objXMLDoc.documentElement.selectNodes(xmlQuery);
var numNodes;
numNodes=docHeadlines.length;
var nn;
for(var i=0;i<numNodes;i++){
nn = docHeadlines.nextNode();
Response.Write(nn.transformNode(xsl));
}
%>
</table>
</body>
</html>
Person.xml :
<?xml version="1.0" encoding="ISO-8859-1"?>
<PersonList>
<Person><Name>Sonu</Name><Age>25</Age><Gender>Male</Gende
r><PostalCode>99999</PostalCode><City>Thane</City></Person>
<Person><Name>vijay</Name><Age>23</Age><Gender>Male</Gend
er><PostalCode>121</PostalCode><City>mumbai</City></Person></P
ersonList>
Person.xsl :
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="Person">
<tr>
</tr>
</xsl:template>
</xsl:stylesheet>
Output:
B] XML Database
Table created.
1 row created.
1 row created.
1 row created.
SQL> insert into emp_xml15 values(1,XMLtype(
'<emp id="4">
<name> nancy </name>
<email>nancyshah@yahoo.com</email>
<acc_no>2343678</acc_no>
<mgr_email>ekta.shah@hotmail.com</mgr_email>
<doj>21/5/2002</doj>
</emp>'));
1 row created.
1 row created.
1 row created.
1 row created.
SQL> insert into emp_xml15 values(2,XMLtype(
'<emp id="8">
1 row created.
Queries:
Output:
EMP_NAME
--------------------------------------------------------------------------------
sharmila
anita
ekta
nancy
falguni
sweta
aarti
sandy
SQL>select e.employee_spec.extract('//acc_no/text()').getStringVal()
"Acc_No" from emp_xml15 e;
Output:
Acc_No
------------------------------------------------------------------------------
23456
234346
2343456
2343678
2343345
Output:
d) Update the 3rd record from the table and display the name of
an employee:
SQL> update emp_xml15 e set employee_spec=XMLtype('<emp id="3">
<name> ekta </name>
<email>ektabhatt@yahoo.com</email>
<acc_no>2343456</acc_no>
<mgr_email>ekta.bhatt@hotmail.com</mgr_email>
<doj>24/5/2001</doj>
<update>This is the updated record</update>
</emp>')
where
e.employee_spec.extract('//name/text()').getStringVal()
='ekta';
Output:
NAME
-------------------------------------------------------------------------------
EMP_SPECIFICATION
-------------------------------------------------------------------------------
ekta
<emp id="3">
<name> ekta </name>
<email>ektabhatt@yahoo.com</email>
<acc_no>2343456</acc_no>
<mgr_email>ekta.bhatt@hotmail.com</mgr_email>
<doj>24/5/2001</doj>
<update>This is the updated record</update>
</emp>
Output:
NAME
--------------------------------------------------------------------------------
sharmila
anita
ekta
falguni
sweta
aarti