ADBMS Practicals
ADBMS Practicals
Distributed Databases –
3
Replication
Distributed Databases-
4
Horizontal Fragmentation
6 XML Databases
7 Temporal Databases
10 Spatial Databases
PRACTICAL NO: 1
SQL> Create or replace type AddrType1 as object(
2 Pincode number(5),
3 Street char(20),
4 City varchar2(50),
5 state varchar2(40),
6 no number(4) )
7 /
Type created.
Type created.
Type created.
Type created.
SQL> create table authors of AuthorType;
Table created.
Type created.
Type created.
Table created.
Table created.
1 row created.
SQL> insert into Authors
values('Ravi',AddrType1(7007,'sstreet','mumbai','mha',1007));
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
SQL> insert into Publishers
values('Priya',AddrType1(4002,'rstreet','mumbai','mha',03),BranchTableTy
pe(BranchType(AddrType1(5002,'fstreet','mumbai','mha',03),23406,69896)));
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
SQL> insert into books select 'DSP','28-may-
1983',ref(pub),AuthorListType(ref(aut)) from Publishers
pub,Authors aut where pub.name='john' and aut.name='Eena';
1 row created.
2 rows created.
2 rows created.
a) List all of the authors that have the same address as their publisher:
NAME
--------------------------------------------------
Ravi
Paul
b) List all of the authors that have the same pin code as their publisher:
NAME
--------------------------------------------------
Ravi
Sanjay
Paul
no rows selected
d) List the title of the book that has the most authors:
TITLE
--------------------------------------------------
c
compiler
e) List the name of the publisher that has the most branches:
NAME
--------------------------------------------------
eklavya
SQL> select a.name from authors a where not exists(select b.title from books
b, table(select authors
from books b1 where b.title = b1.title) a2 where a.name = name);
no rows selected
g) Move all the branches that belong to the publisher 'tata' to the publisher
‘joshi'
2 rows created.
h) List all authors who have published more than one book:
NAME
--------------------------------------------------
Jharna
Ravi
i) 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 is unique in a list of authors has not been specified).
TITLE
--------------------------------------------------
c
compiler
PRACTICAL NO: 2
SQL> create or replace type state61 as object
2 (
3 st_code number(5),
4 st_name varchar2(40),
5 st_district varchar2(50),
6 st_pincode number(7)
7 )
8 /
Type created.
SQL> create or replace type contact_detail61 as object
2 (
3 residence_no number(10),
4 office_no number(10),
5 email varchar2(30),
6 fax number(10),
7 mobile number(10)
8 )
9 /
Type created.
Type created.
SQL> create or replace type staff61 as object(
2 staff_id number(6),
3 staff_name varchar2(40),
4 staff_address address61,
5 staff_deptno number(3),
6 staff_sal number(6),
7 staff_other varchar2(40),
8 dob date,
9 member function getAge return number)
10 /
Type created.
SQL> create or replace type body staff61 as member function getAge return
number as
2 begin
3 return trunc(months_between(sysdate,dob)/12);
4 end getAge;
5 end;
6 /
Type created.
SQL> create or replace type dept61 as object
2 (
3 dept_id number(3),
4 location varchar2(30),
5 dept_name varchar2(20),
6 emp staffTableType
7 )
8 /
Type created.
Table created.
1 row created.
1 row created.
SQL> insert into dpt_refernce
values(2,'Mumbai','Accounts',staffTableType(staff61(3,'Sharmila Dave',
address61('C-1','M.G. road','Sanjeevani
Hospital',state61(1,'Maharashtra','Mumbai',400078),contact_d
etail61(28331112,28987058,'sam_dave@hotmail.com',28982430,9833196734)),
2,2000,'clerk','28-sep-1984')
));
1 row created.
1 row created.
1 row created.
a) Display staff ID and department name of all employees.
DEPT_NAME STAFF_ID
-------------------- ----------
Sales 1
Sales 2
Accounts 3
Purchase 4
Purchase 5
DEPT_ID DEPT_NAME
---------- --------------------
1 Sales
d) Display department-wise report
DOB AGE
--------- ----------
17-AUG-84 28
PRACTICAL NO: 3
Table created.
Table created.
SQL> connect scott/tiger @replic1 as sysdba
Connected.
SQL> create public database link r connect to scott identified by tiger
using'replic' ;
1 create or replace trigger trig after insert on employee for each row
2 begin
3 insert into employee1@r1
4 values(:new.eno,:new.ename,:new.address,:new.email,:new.salary);
5* end;
SQL> /
Trigger created.
SQL> ed
Wrote file afiedt.buf
1 insert into employee(eno,ename,address,email,salary)
2* values(&eno,'&ename','&address','&email',&salary)
SQL> /
Enter value for eno: 1
Enter value for ename: anshu
Enter value for address: nsp
Enter value for email: a@yahoo.com
Enter value for salary: 1000
old 2: values(&eno,'&ename','&address','&email',&salary)
new 2: values(1,'anshu','nsp','a@yahoo.com',1000)
1 row created.
SQL> ed
Wrote file afiedt.buf
1 row created.
SQL> ed
Wrote file afiedt.buf
1 row created.
SQL> ed
Wrote file afiedt.buf
1 row created.
SQL> ed
Wrote file afiedt.buf
1 row created.
SQL> ed
Wrote file afiedt.buf
1 row created.
SQL> ed
Wrote file afiedt.buf
1 row created.
SQL> ed
Wrote file afiedt.buf
1 row created.
SQL> ed
Wrote file afiedt.buf
1 row created.
SQL> ed
Wrote file afiedt.buf
1 row created.
10 rows selected.
SQL> select * from employee1@r1 ;
10 rows selected.
SQL> ed
Wrote file afiedt.buf
1 select eno,salary from employee union select eno,salary from
employee1@r1
SQL> /
ENO SALARY
---------- ----------
1 1000
2 8000
3 15000
4 3500
5 10000
6 11000
7 2000
8 13000
9 15000
10 16000
10 rows selected.
SQL> ed
Wrote file afiedt.buf
ENO EMAIL
---------- ---------------
3 s@yahoo.com
9 ra@yahoo.com
SQL> ed
Wrote file afiedt.buf
ENAME EMAIL
---------- ---------------
bhavan bh@yahoo.com
SQL> ed
Wrote file afiedt.buf
ENAME ADDRESS
---------- ---------------
shiv andheri
PRACTICAL NO: 4
SQL> connect scott/tiger @horiz
Connected.
SQL> ed
Wrote file afiedt.buf
Table created.
SQL> ed
Wrote file afiedt.buf
1 row created.
SQL> ed
Wrote file afiedt.buf
1 row created.
SQL> ed
Wrote file afiedt.buf
1 row created.
SQL> ed
Wrote file afiedt.buf
1 row created.
SQL> ed
Wrote file afiedt.buf
1 row created.
SQL> ed
Wrote file afiedt.buf
1 row created.
SQL> ed
Wrote file afiedt.buf
1 insert into employee(eno,ename,address,email,salary)
2* values(&eno,'&ename','&address','&email',&salary)
SQL> /
Enter value for eno: 7
Enter value for ename: Ivan
Enter value for address: kandivali
Enter value for email: I@yahoo.com
Enter value for salary: 2000
old 2: values(&eno,'&ename','&address','&email',&salary)
new 2: values(7,'Ivan','kandivali','I@yahoo.com',2000)
1 row created.
SQL> ed
Wrote file afiedt.buf
1 row created.
SQL> ed
Wrote file afiedt.buf
1 row created.
SQL> ed
Wrote file afiedt.buf
1 row created.
10 rows selected.
SQL> connect scott/tiger @horiz as sysdba
Connected.
SQL> create public database link link12 connect to scott identified by tiger
using 'horiz1' ;
Table created.
9 rows selected.
SQL> ed
Wrote file afiedt.buf
Table created.
7 rows selected.
SQL> select eno,salary from emp1 union select eno,salary from emp2
@link12;
ENO SALARY
---------- ----------
1 10000
2 8000
3 15000
4 35000
5 100000
6 11000
7 20000
8 13000
9 150000
10 160000
10 rows selected.
SQL> ed
Wrote file afiedt.buf
ENO EMAIL
---------- ---------------
3 s@yahoo.com
SQL> ed
Wrote file afiedt.buf
ENAME EMAIL
---------- ---------------
shiv sh@yahoo.com
SQL> ed
Wrote file afiedt.buf
ENAME ADDRESS
---------- ---------------
Ivan kandivali
PRACTICAL NO: 5
SQL> connect scott/tiger @verti
Connected.
SQL> create table employee(eno number(3),ename varchar2(10),address
varchar2(15),
2 email varchar2(15),salary number(10)) ;
Table created.
1 row created.
SQL> ed
Wrote file afiedt.buf
1 insert into employee(eno,ename,address,email,salary)
2* values(&eno,'&ename','&address','&email',&salary)
SQL> /
Enter value for eno: 2
Enter value for ename: ravi
Enter value for address: mira road
Enter value for email: r@yahoo.com
Enter value for salary: 140000
old 2: values(&eno,'&ename','&address','&email',&salary)
new 2: values(2,'ravi','mira road','r@yahoo.com',140000)
1 row created.
SQL> ed
Wrote file afiedt.buf
1 row created.
SQL> ed
Wrote file afiedt.buf
1 row created.
SQL> ed
Wrote file afiedt.buf
1 row created.
SQL> ed
Wrote file afiedt.buf
1 row created.
SQL> ed
Wrote file afiedt.buf
1 row created.
SQL> ed
Wrote file afiedt.buf
1 row created.
SQL> ed
Wrote file afiedt.buf
1 row created.
SQL> ed
Wrote file afiedt.buf
1 row created.
SQL> select * from employee;
10 rows selected.
Table created.
SQL> select * from emp1;
10 rows selected.
Table created.
SQL> select * from emp2;
10 rows selected.
ENO SALARY
---------- ----------
5 10000
ENO EMAIL
---------- ---------------
1 a@yahoo.com
SQL> select emp1.ename,emp2.email from emp2 , emp1 @a1
2 where emp1.eno=3 and emp1.eno=emp2.eno;
ENAME EMAIL
---------- ---------------
shree s@yahoo.com
ENAME SALARY
---------- ----------
anshu 100000
ravi 140000
shree 15000
Bhavesh 35000
Jharna 10000
jarishma 11000
shiv 1500000
rashmi 160000
Bhavan 16000
9 rows selected.
PRACTICAL NO: 6
Create different Types and Tables
Table created.
1 row created.
SQL> insert into emp_xml15 values(1,XMLtype(
2 '<emp id="2">
3 <name> anita </name>
4 <email>ani@yahoo.com</email>
5 <acc_no>234346</acc_no>
6 <mgr_email>rekha.shah@hotmail.com</mgr_email>
7 <doj>2/6/2003</doj>
8 </emp>'));
1 row created.
SQL> insert into emp_xml15 values(1,XMLtype(
2 '<emp id="3">
3 <name> ekta </name>
4 <email>ektabhatt@yahoo.com</email>
5 <acc_no>2343456</acc_no>
6 <mgr_email>ekta.bhatt@hotmail.com</mgr_email>
7 <doj>24/5/2001</doj>
8 </emp>'));
1 row created.
1 row created.
1 row created.
SQL> insert into emp_xml15 values(1,XMLtype(
2 '<emp id="6">
3 <name> sweta </name>
4 <email>swetamehta@yahoo.com</email>
5 <acc_no>2343890</acc_no>
6 <mgr_email>sweta.mehta@hotmail.com</mgr_email>
7 <doj>2/1/2001</doj>
8 </emp>'));
1 row created.
1 row created.
1 row created.
Firing queries on the created tables
Output:
EMP_NAME
--------------------------------------------------------------------------------
sharmila
anita
ekta
nancy
falguni
sweta
aarti
sandy
8 rows selected.
SQL>select e.employee_spec.extract('//acc_no/text()').getStringVal()
2* "Acc_No" from emp_xml15 e;
Output:
Acc_No
------------------------------------------------------------------------------
23456
234346
2343456
2343678
2343345
2343890
23433898
23567898
8 rows selected.
Output:
8 rows selected.
d) Update the 3rd record from the table and display the name of an employee:
1 row updated.
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>
e) Delete the 4th record from the table:
1 row deleted.
Output:
NAME
--------------------------------------------------------------------------------
sharmila
anita
ekta
falguni
sweta
aarti
6 rows selected.
PRACTICAL NO: 7-A
SQL> create table customer
2 (
3 cust_name varchar(10),
4 customer_no number(5),
5 open_date timestamp(2),
6 transac_time timestamp(2)
7 )
8 ;
Table created.
1 row created.
1 row created.
1 row created.
SQL> insert into customer values('dhara',2002,'23-feb-1992 5.30.00.000000
pm','13-dec-2006 12.00 pm'
);
1 row created.
1 row created.
CUST_NAME CUSTOMER_NO
---------- -----------
OPEN_DATE
---------------------------------------------------------------------------
TRANSAC_TIME
---------------------------------------------------------------------------
keyur 1
12-AUG-11 01.00.00.00 PM
14-SEP-20 12.10.00.00 AM
shlok 2
18-FEB-83 08.45.00.00 PM
14-JAN-20 11.09.23.01 AM
CUST_NAME CUSTOMER_NO
---------- -----------
OPEN_DATE
---------------------------------------------------------------------------
TRANSAC_TIME
---------------------------------------------------------------------------
shruti 2023
16-JAN-00 10.30.00.00 AM
10-JUN-20 04.03.30.00 PM
dhara 2002
23-FEB-92 05.30.00.00 PM
CUST_NAME CUSTOMER_NO
---------- -----------
OPEN_DATE
---------------------------------------------------------------------------
TRANSAC_TIME
---------------------------------------------------------------------------
13-DEC-20 06.12.00.00 PM
akash 2012
24-SEP-02 04.30.00.00 PM
12-JUL-20 05.09.30.00 AM
no rows selected
SQL> select * from customer where to_char(open_date,'hh.mi am') like '10.30
am';
CUST_NAME CUSTOMER_NO
---------- -----------
OPEN_DATE
---------------------------------------------------------------------------
TRANSAC_TIME
---------------------------------------------------------------------------
shruti 2023
16-JAN-00 10.30.00.00 AM
10-JUN-20 04.03.30.00 PM
no rows selected
no rows selected
no rows selected
SQL> select * from customer where to_char(open_date,'dd')='18';
CUST_NAME CUSTOMER_NO
---------- -----------
OPEN_DATE
---------------------------------------------------------------------------
TRANSAC_TIME
---------------------------------------------------------------------------
shlok 2
18-FEB-83 08.45.00.00 PM
14-JAN-20 11.09.23.01 AM
CUST_NAME CUSTOMER_NO
---------- -----------
OPEN_DATE
---------------------------------------------------------------------------
TRANSAC_TIME
---------------------------------------------------------------------------
dhara 2002
23-FEB-92 05.30.00.00 PM
13-DEC-20 06.12.00.00 PM
COUNT(OPEN_DATE)
----------------
2
PRACTICAL NO: 7-B
Table definition :
Table created.
1 row created.
1 row created.
1 row created.
SQL> insert into tbl_shares15 values('Patni',115,15,'08-may-01
07.25.00.000000
am');
1 row created.
1 row created.
1 row created.
SQL> insert into tbl_shares15 values('Hero Honda',100,250,'21-aug-04
05.30.00.000000 pm');
1 row created.
SQL> select * from tbl_shares15;
Output:
5 rows selected.
QUERIES :
1) Find all the names of a company whose share price is more than Rs.100 at
11:45 A.M.
SQL> /
Output:
cname
--------------------
Tata
2) Find the name of company which has highest shares price at 5.00 P.M.
SQL> /
Output:
cname
--------------------
Hero Honda
PRACTICAL NO: 8
Create different Types and Tables
Table created.
Table created.
1 row created.
1 row created.
SQL> insert into Empl values(3,'sharmila',3,10,1003);
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
a) Creating a trigger to insert new employee tuple and display the new
total hours from project table.
Trigger:
Trigger created.
/*Inserting values in Empl to so that trigger will be fired on project table
&will update thrs value since trigger is fired after inserting value in empl
table*/
SQL> insert into Empl values(11,'nancy',4,30,1011);
1 row created.
Output:
Trigger created.
SQL> update Empl
set hrs=10
where eno=11;
1 row updated.
Ouput:
Trigger created.
SQL> update Empl
set pno=10
where eno=2;
1 row updated.
1 row updated.
Output:
Trigger:
SQL> create trigger thrs4
after delete on Empl
for each row
when(OLD.pno IS NOT NULL)
begin
update project
set thrs=thrs-:OLD.hrs
where pno=:OLD.pno;
end;
Trigger created.
1 row deleted.
Table created.
Table created.
1 row created.
1 row created.
SQL> insert into Empl values(3,'sharmila',3,10,1003);
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
Trigger:
Trigger created.
Table created.
1 row created.
1 row created.
1 row created.
1 row created.
SQL>insert into user_sdo_geom_metadata values (
1 ‘university_15’,
2 ‘shape’,
3 mdsys.sdo_dim_array(
4 mdsys.sdo_dim_element(‘x’, 0, 20, 0.005),
5 mdsys.sdo_dim_element(‘y’, 0, 20, 0.005)
6 ),
7 null -- srid
8 );
1 row created.
Index created.
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))
2) Find whether two geometric figures are equivalent to each other.
Output:
SDO_GEOM.RELATE(C_B.SHAPE,'ANYINTERACT',C_D.SHAPE,0.005)
--------------------------------------------------------------------------------
FALSE
Output:
SDO_GEOM.RELATE(C_B.SHAPE,'ANYINTERACT',C_A.SHAPE,0.005)
--------------------------------------------------------------------------------
TRUE
Output:
NAME SDO_GEOM.SDO_AREA(SHAPE,0.005)
-------------------------------- ------------------------------
abc 24
pqr 16.5
mno 5
xyz 12.5663706
4) Find the area of only one location abc.
Output:
NAME SDO_GEOM.SDO_AREA(C.SHAPE,0.005)
-------------------------------- --------------------------------
abc 24
Output:
SDO_GEOM.SDO_DISTANCE(C_B.SHAPE,C_D.SHAPE,0.005)
------------------------------------------------
.846049894