adbms practicals

Upload: rntime

Post on 02-Mar-2016

101 views

Category:

Documents


3 download

DESCRIPTION

Mumbai University, MSC (Computer Science), Semester-2,List of Practicals,Object Oriented,Distributed Database,Xml Database,Temporal Database,Active Database,Spatial Database.

TRANSCRIPT

  • INDEX

    SR. NO. TOPIC DATE SIGN

    1 Object Oriented Databases Simple Examples

    2 Object Oriented Databases Nested Tables

    3 Distributed Databases Replication

    4 Distributed Databases-Horizontal Fragmentation

    5 Distributed Databases - VerticalFragmentation

    6 XML Databases

    7 Temporal Databases

    8 Active Databases- Row leveltriggers

    9 Active Databases- Statementlevel triggers

    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.

    SQL> create or replace type BranchType as object(2 address AddrType1,3 phone1 integer,4* phone2 integer )5 /

    Type created.

    SQL> create or replace type BranchTableType as table of BranchType;2 /

    Type created.

    SQL> create or replace type AuthorType as object(2 name varchar2(50),3* addr AddrType1 )4 /

    Type created.

  • SQL> create table authors of AuthorType;

    Table created.

    SQL> create or replace type AuthorListType as varray(10) of ref AuthorType2 /

    Type created.

    SQL> create or replace type PublisherType as object(2 name varchar2(50),3* addr AddrType1, branches BranchTableType)4 /

    Type created.

    SQL> create table Publishers of PublisherType NESTED TABLE branchesSTORE as branchtable2 /

    Table created.

    SQL> create table books(2 title varchar2(50),3 year date,4 published_by ref PublisherType,5* authors AuthorListType)6 /

    Table created.

    SQL> insert into Authorsvalues('Ravi',AddrType1(5002,'sstreet','pune','mha',04));

    1 row created.

  • SQL> insert into Authorsvalues('Ravi',AddrType1(7007,'sstreet','mumbai','mha',1007));

    1 row created.

    SQL> insert into Authorsvalues('Sanjay',AddrType1(7008,'nstreet','nasik','mha',08));

    1 row created.

    SQL> insert into Authorsvalues('Jharna',AddrType1(7003,'dstreet','mumbai','mha',1003));

    1 row created.

    SQL> insert into Authorsvalues('Paul',AddrType1(7008,'sstreet','mumbai','mha',1007));

    1 row created.

    SQL> insert into Authorsvalues('Eena',AddrType1(7006,'nstreet','mumbai','mha',1006));

    1 row created.

    SQL> insert into Authorsvalues('Rama',AddrType1(8002,'dstreet','pune','mha',1003));

    1 row created.

    SQL> insert into Authorsvalues('Jharna',AddrType1(8003,'dstreet','pune','mha',1003));

    1 row created.

  • SQL> insert into Publishersvalues('Priya',AddrType1(4002,'rstreet','mumbai','mha',03),BranchTableType(BranchType(AddrType1(5002,'fstreet','mumbai','mha',03),23406,69896)));

    1 row created.

    SQL> insert into Publishersvalues('eklavya',AddrType1(7007,'sstreet','mumbai','mha',1007),BranchTableType(BranchType(AddrType1(7007,'sstreet','mumbai','mha',1007),4543545,8676775)));

    1 row created.

    SQL> insert into Publishersvalues('john',AddrType1(7008,'sstreet','mumbai','mha',1007),BranchTableType(BranchType(AddrType1(1002,'sstreet','nasik','mha',1007),456767,7675757)));

    1 row created.

    SQL> insert into Publishersvalues('eklavya',AddrType1(7002,'sstreet','pune','mha',1007),BranchTableType(BranchType(AddrType1(1002,'sstreet','pune','mha',1007),4543545,8676775)));

    1 row created.

    SQL> insert into Publishersvalues('william',AddrType1(6002,'sstreet','nasik','mha',1007),BranchTableType(BranchType(AddrType1(6002,'sstreet','nasik','mha',1007),4543545,8676775)));

    1 row created.

  • SQL> insert into books select 'DSP','28-may-1983',ref(pub),AuthorListType(ref(aut)) from Publisherspub,Authors aut where pub.name='john' and aut.name='Eena';

    1 row created.

    SQL> insert into books select 'compiler','09-jan-1890',ref(pub),AuthorListType(ref(aut)) from Publishers pub,Authors aut where pub.name='william' and aut.name='Jharna';

    2 rows created.

    SQL> insert into books select 'c','25-may-1983',ref(pub),AuthorListType(ref(aut)) from Publishers pub,Authors aut where pub.name='Priya' and aut.name='Ravi';

    2 rows created.

    a) List all of the authors that have the same address as their publisher:

    SQL> select a.name from authors a, publishers p where a.addr = p.addr;

    NAME--------------------------------------------------

    RaviPaul

  • b) List all of the authors that have the same pin code as their publisher:

    SQL> select a.name from authors a, publishers p where a.addr.pincode =p.addr.pincode;

    NAME--------------------------------------------------

    RaviSanjayPaul

    c) List all books that have 2 or more authors:

    SQL> select * from books b where 1 Select title from books b, table(b.authors) group by title havingcount(*)=(select max(count(*)) from books b, table(b.authors) group by title)2 /

    TITLE--------------------------------------------------

    c

    compiler

  • e) List the name of the publisher that has the most branches:

    SQL> Select p.name from publishers p, table(p.branches) group by p.namehaving count(*)>=all (selectcount(*) from publishers p, table(p.branches) group by name);

    NAME--------------------------------------------------

    eklavya

    f) Name of authors who have not published a book:

    SQL> select a.name from authors a where not exists(select b.title from booksb, table(select authorsfrom 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 publisherjoshi'

    SQL> insert into table(select branches from publishers wherename='william') select b.* from publishers p, table(p.branches) b where name= 'eklavya';

    2 rows created.

  • h) List all authors who have published more than one book:

    SQL> select a.name from authors a, books b, table(b.authors) v wherev.column_value = ref(a) group by a.name having count(*) > 1;

    NAME--------------------------------------------------

    JharnaRavi

    i) List all books (title) where the same author appears more than once on thelist of authors (assuming that an integrity constraint requiring that the nameof an author is unique in a list of authors has not been specified).

    SQL> select title from authors a, books b, table(b.authors) v wherev.column_value = ref(a) group bytitle having count(*) > 1;

    TITLE--------------------------------------------------

    c

    compiler

  • PRACTICAL NO: 2SQL> create or replace type state61 as object2 (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 object2 (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.

    SQL> create or replace type address61 as object2 (3 road_no varchar2(7),4 road_name varchar2(40),5 landmark varchar2(40),6 state state61,7 contact contact_detail618* )9 /

    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 returnnumber as2 begin3 return trunc(months_between(sysdate,dob)/12);4 end getAge;5 end;6 /

    Type body created.

    SQL> create or replace type staffTableType as table of staff612 /

    Type created.

  • SQL> create or replace type dept61 as object2 (3 dept_id number(3),4 location varchar2(30),5 dept_name varchar2(20),6 emp staffTableType7 )8 /

    Type created.

    SQL> create table dpt_refernce of dept61 nested table emp store asNTrelation2 /

    Table created.

    SQL> insert into dpt_referncevalues(1,'Mumbai','Sales',staffTableType(staff61(1,'EklavyaSingh',address61('A-1','L.T. road','StatusHotel',state61(1,'Maharashtra','Mumbai',400092),contact_detail61(28994177,28182729,'[email protected]',28994177,9818967345)),1,10000,'HOD','17-aug-1984')));

    1 row created.

    SQL> insert into dpt_referncevalues(1,'Mumbai','Sales',staffTableType(staff61(2,'SanjayShukla',address61('C-1','yariroad','',state61(1,'Maharashtra','Mumbai',400069),contact_detail61(26321115,26331739,'[email protected]',26321116,918967345)),1,6000,'HOD','04-nov-1984')));

    1 row created.

  • SQL> insert into dpt_referncevalues(2,'Mumbai','Accounts',staffTableType(staff61(3,'Sharmila Dave',address61('C-1','M.G. road','SanjeevaniHospital',state61(1,'Maharashtra','Mumbai',400078),contact_detail61(28331112,28987058,'[email protected]',28982430,9833196734)),2,2000,'clerk','28-sep-1984')));

    1 row created.

    SQL> insert into dpt_referncevalues(3,'Mumbai','Purchase',staffTableType(staff61(4,'AnshuDubey',address61('E-2','B.S.road','VikasKendra',state61(2,'Goa','Panji',419832),contact_detail61(26831112,26897058,'[email protected]',26897059,9820636448)),3,7000,'','09-sep-1984')));

    1 row created.

    SQL> insert into dpt_referncevalues(3,'Mumbai','Purchase',staffTableType(staff61(5,'ParthJoshi',address61('E-2','Nehru road','HDFCBank',state61(1,'Maharashtra','Vileparle',400056),contact_detail61(26149172,26157058,'[email protected]',26897059,9820739488)),3,9000,'','29-sep-1985')));

    1 row created.

  • a) Display staff ID and department name of all employees.

    SQL> select p.dept_name, q.staff_id from dpt_refernce p,table(p.emp) q;

    DEPT_NAME STAFF_ID-------------------- ----------

    Sales 1Sales 2Accounts 3Purchase 4Purchase 5

    b) How many workers are in particular department.

    SQL> select p.dept_id,p.dept_name,count(q.staff_id) asnumber_of_employees from dpt_refernce p,table(p.emp) q where p.dept_name='Purchase' group by dept_id,dept_name;

    DEPT_ID DEPT_NAME NUMBER_OF_EMPLOYEES---------- -------------------- -------------------

    3 Purchase 2

    c) Find department name for particular staff name

    SQL> select p.dept_id,p.dept_name from dpt_refernce p,table(p.emp) qwhere q.staff_name='EklavyaSingh';

    DEPT_ID DEPT_NAME---------- --------------------

    1 Sales

  • d) Display department-wise report

    SQL> select p.dept_id,p.dept_name,count(q.staff_id) asnumber_of_employees from dpt_refernce p,table(p.emp) q group by p.dept_id,p.dept_name ;

    DEPT_ID DEPT_NAME NUMBER_OF_EMPLOYEES---------- -------------------- -------------------

    1 Sales 22 Accounts 13 Purchase 2

    e) Display age and birth date of particular employee

    SQL> select q.dob,q.getAge() as Age from dpt_refernce p,table(p.emp) qwhere q.staff_name='EklavyaSingh';

    DOB AGE--------- ----------

    17-AUG-84 28

  • PRACTICAL NO: 3

    SQL> connect scott/tiger @replicConnected.SQL> edWrote file afiedt.buf

    1 create table employee(eno number(3),ename varchar2(10),addressvarchar2(15),2* email varchar2(15),salary number(10))

    SQL> /

    Table created.

    SQL> connect scott/tiger @replic as sysdbaConnected.SQL> edWrote file afiedt.buf1 create public database link r1 connect to scott identified2* by tiger using 'replic1'

    SQL> /Database link created.SQL> connect scott/tiger @replic1Connected.SQL> edWrote file afiedt.buf

    1 create table employee1(eno number(3),ename varchar2(10),addressvarchar2(15),2* email varchar2(15),salary number(10))

    SQL> /

    Table created.

  • SQL> connect scott/tiger @replic1 as sysdbaConnected.SQL> create public database link r connect to scott identified by tigerusing'replic' ;

    Database link created.

    SQL> connect scott/tiger @replicConnected.SQL> edWrote file afiedt.buf

    1 create or replace trigger trig after insert on employee for each row2 begin3 insert into employee1@r14 values(:new.eno,:new.ename,:new.address,:new.email,:new.salary);5* end;

    SQL> /Trigger created.

    SQL> edWrote file afiedt.buf1 insert into employee(eno,ename,address,email,salary)2* values(&eno,'&ename','&address','&email',&salary)

    SQL> /Enter value for eno: 1Enter value for ename: anshuEnter value for address: nspEnter value for email: [email protected] value for salary: 1000old 2: values(&eno,'&ename','&address','&email',&salary)new 2: values(1,'anshu','nsp','[email protected]',1000)

    1 row created.

  • SQL> edWrote file afiedt.buf

    1 insert into employee(eno,ename,address,email,salary)2* values(&eno,'&ename','&address','&email',&salary)

    SQL> /Enter value for eno: 2Enter value for ename: raviEnter value for address: mira roadEnter value for email: [email protected] value for salary: 8000old 2: values(&eno,'&ename','&address','&email',&salary)new 2: values(2,'ravi','mira road','[email protected]',8000)

    1 row created.

    SQL> edWrote file afiedt.buf

    1 insert into employee(eno,ename,address,email,salary)2* values(&eno,'&ename','&address','&email',&salary)

    SQL> /Enter value for eno: 3Enter value for ename: shreeEnter value for address: bhynderEnter value for email: [email protected] value for salary: 15000old 2: values(&eno,'&ename','&address','&email',&salary)new 2: values(3,'shree','bhynder','[email protected] ',15000)

    1 row created.

  • SQL> edWrote file afiedt.buf

    1 insert into employee(eno,ename,address,email,salary)2* values(&eno,'&ename','&address','&email',&salary)

    SQL> /Enter value for eno: 4Enter value for ename: BhaveshEnter value for address: vasaiEnter value for email: [email protected] value for salary: 3500old 2: values(&eno,'&ename','&address','&email',&salary)new 2: values(4,'Bhavesh','vasai','[email protected]',3500)

    1 row created.

    SQL> edWrote file afiedt.buf

    1 insert into employee(eno,ename,address,email,salary)2* values(&eno,'&ename','&address','&email',&salary)

    SQL> /Enter value for eno: 5Enter value for ename: JharnaEnter value for address: naigaonEnter value for email: [email protected] value for salary: 10000old 2: values(&eno,'&ename','&address','&email',&salary)new 2: values(5,'Jharna','naigaon','[email protected]',10000)

    1 row created.

  • SQL> edWrote file afiedt.buf

    1 insert into employee(eno,ename,address,email,salary)2* values(&eno,'&ename','&address','&email',&salary)

    SQL> /Enter value for eno: 6Enter value for ename: karishmaEnter value for address: borivaliEnter value for email: [email protected] value for salary: 11000old 2: values(&eno,'&ename','&address','&email',&salary)new 2: values(6,'karishma','borivali','[email protected]',11000)

    1 row created.

    SQL> edWrote file afiedt.buf

    1 insert into employee(eno,ename,address,email,salary)2* values(&eno,'&ename','&address','&email',&salary)

    SQL> /Enter value for eno: 7Enter value for ename: IvanEnter value for address: kandivaliEnter value for email: [email protected] value for salary: 2000old 2: values(&eno,'&ename','&address','&email',&salary)new 2: values(7,'Ivan','kandivali','[email protected]',2000)

    1 row created.

  • SQL> edWrote file afiedt.buf

    1 insert into employee(eno,ename,address,email,salary)2* values(&eno,'&ename','&address','&email',&salary)

    SQL> /Enter value for eno: 8Enter value for ename: shivEnter value for address: andheriEnter value for email: [email protected] value for salary: 13000old 2: values(&eno,'&ename','&address','&email',&salary)new 2: values(8,'shiv','andheri','[email protected]',13000)

    1 row created.

    SQL> edWrote file afiedt.buf

    1 insert into employee(eno,ename,address,email,salary)2* values(&eno,'&ename','&address','&email',&salary)

    SQL> /Enter value for eno: 9Enter value for ename: rashmiEnter value for address: jogeshwariEnter value for email: [email protected] value for salary: 15000old 2: values(&eno,'&ename','&address','&email',&salary)new 2: values(9,'rashmi','jogeshwari','[email protected]',15000)

    1 row created.

  • SQL> edWrote file afiedt.buf

    1 insert into employee(eno,ename,address,email,salary)2* values(&eno,'&ename','&address','&email',&salary)

    SQL> /Enter value for eno: 10Enter value for ename: bhavanEnter value for address: dahisarEnter value for email: [email protected] value for salary: 16000old 2: values(&eno,'&ename','&address','&email',&salary)new 2: values(10,'bhavan','dahisar','[email protected]',16000)

    1 row created.

    SQL> select * from employee ;

    ENO ENAME ADDRESS EMAIL SALARY---------- ---------- --------------- --------------- ----------

    1 anshu nsp [email protected] 10002 ravi mira road [email protected] 80003 shree bhynder [email protected] 150004 Bhavesh vasai [email protected] 35005 Jharna naigaon [email protected] 100006 karishma borivali [email protected] 110007 Ivan kandivali [email protected] 20008 shiv andheri [email protected] 130009 rashmi jogeshwari [email protected] 15000

    10 bhavan dahisar [email protected] 16000

    10 rows selected.

  • SQL> select * from employee1@r1 ;

    ENO ENAME ADDRESS EMAIL SALARY---------- ---------- --------------- --------------- ----------

    1 anshu nsp [email protected] 10002 ravi mira road [email protected] 80003 shree bhynder [email protected] 150004 Bhavesh vasai [email protected] 35005 Jharna naigaon [email protected] 100006 karishma borivali [email protected] 110007 Ivan kandivali [email protected] 20008 shiv andheri [email protected] 130009 rashmi jogeshwari [email protected] 15000

    10 bhavan dahisar [email protected] 16000

    10 rows selected.SQL> edWrote file afiedt.buf1 select eno,salary from employee union select eno,salary from

    employee1@r1SQL> /

    ENO SALARY---------- ----------

    1 10002 80003 150004 35005 100006 110007 20008 130009 15000

    10 1600010 rows selected.

  • SQL> edWrote file afiedt.buf

    1 select eno,email from employee where salary=15000 union select eno,email2* from employee1@r1 where salary=15000

    SQL> /

    ENO EMAIL---------- ---------------

    3 [email protected] [email protected]

    SQL> edWrote file afiedt.buf

    1 select ename,email from employee where eno=10 union2* select ename,email from employee1@r1 where eno=10

    SQL> /

    ENAME EMAIL---------- ---------------

    bhavan [email protected]

    SQL> edWrote file afiedt.buf

    1 select ename,address from employee where eno=8 union2* select ename,address from employee1@r1 where eno=8

    SQL> /

    ENAME ADDRESS---------- ---------------

    shiv andheri

  • PRACTICAL NO: 4SQL> connect scott/tiger @horizConnected.

    SQL> edWrote file afiedt.buf

    1 create table employee(eno number(3),ename varchar2(10),addressvarchar2(15),2* email varchar2(15),salary number(10))

    SQL> /

    Table created.

    SQL> edWrote file afiedt.buf

    1 insert into employee(eno,ename,address,email,salary)2* values(&eno,'&ename','&address','&email',&salary)

    SQL> /Enter value for eno: 1Enter value for ename: anshuEnter value for address: nspEnter value for email: [email protected] value for salary: 1000old 2: values(&eno,'&ename','&address','&email',&salary)new 2: values(1,'anshu','nsp','[email protected]',1000)

    1 row created.

  • SQL> edWrote file afiedt.buf

    1 insert into employee(eno,ename,address,email,salary)2* values(&eno,'&ename','&address','&email',&salary)

    SQL> /Enter value for eno: 2Enter value for ename: raviEnter value for address: mira roadEnter value for email: [email protected] value for salary: 8000old 2: values(&eno,'&ename','&address','&email',&salary)new 2: values(2,'ravi','mira road','[email protected]',8000)

    1 row created.

    SQL> edWrote file afiedt.buf

    1 insert into employee(eno,ename,address,email,salary)2* values(&eno,'&ename','&address','&email',&salary)

    SQL> /Enter value for eno: 3Enter value for ename: shreeEnter value for address: bhynderEnter value for email: [email protected] value for salary: 15000old 2: values(&eno,'&ename','&address','&email',&salary)new 2: values(3,'shree','bhynder','[email protected]',15000)

    1 row created.

  • SQL> edWrote file afiedt.buf

    1 insert into employee(eno,ename,address,email,salary)2* values(&eno,'&ename','&address','&email',&salary)

    SQL> /Enter value for eno: 4Enter value for ename: BhaveshEnter value for address: vasaiEnter value for email: [email protected] value for salary: 3500old 2: values(&eno,'&ename','&address','&email',&salary)new 2: values(4,'Bhavesh','vasai','[email protected]',3500)

    1 row created.

    SQL> edWrote file afiedt.buf

    1 insert into employee(eno,ename,address,email,salary)2* values(&eno,'&ename','&address','&email',&salary)

    SQL> /Enter value for eno: 5Enter value for ename: JharnaEnter value for address: naigaonEnter value for email: [email protected] value for salary: 10000old 2: values(&eno,'&ename','&address','&email',&salary)new 2: values(5,'Jharna','naigaon','[email protected]',10000)

    1 row created.

  • SQL> edWrote file afiedt.buf

    1 insert into employee(eno,ename,address,email,salary)2* values(&eno,'&ename','&address','&email',&salary)

    SQL> /Enter value for eno: 6Enter value for ename: karishmaEnter value for address: borivaliEnter value for email: [email protected] value for salary: 11000old 2: values(&eno,'&ename','&address','&email',&salary)new 2: values(6,'karishma','borivali','[email protected]',11000)

    1 row created.

    SQL> edWrote file afiedt.buf1 insert into employee(eno,ename,address,email,salary)2* values(&eno,'&ename','&address','&email',&salary)

    SQL> /Enter value for eno: 7Enter value for ename: IvanEnter value for address: kandivaliEnter value for email: [email protected] value for salary: 2000old 2: values(&eno,'&ename','&address','&email',&salary)new 2: values(7,'Ivan','kandivali','[email protected]',2000)

    1 row created.

  • SQL> edWrote file afiedt.buf

    1 insert into employee(eno,ename,address,email,salary)2* values(&eno,'&ename','&address','&email',&salary)

    SQL> /Enter value for eno: 8Enter value for ename: shivEnter value for address: andheriEnter value for email: [email protected] value for salary: 13000old 2: values(&eno,'&ename','&address','&email',&salary)new 2: values(8,'shiv','andheri','[email protected]',13000)

    1 row created.

    SQL> edWrote file afiedt.buf

    1 insert into employee(eno,ename,address,email,salary)2* values(&eno,'&ename','&address','&email',&salary)

    SQL> /Enter value for eno: 9Enter value for ename: rashmiEnter value for address: jogeshwariEnter value for email: [email protected] value for salary: 15000old 2: values(&eno,'&ename','&address','&email',&salary)new 2: values(9,'rashmi','jogeshwari','[email protected]',15000)

    1 row created.

  • SQL> edWrote file afiedt.buf

    1 insert into employee(eno,ename,address,email,salary)2* values(&eno,'&ename','&address','&email',&salary)

    SQL> /Enter value for eno: 10Enter value for ename: bhavanEnter value for address: dhaisarEnter value for email: [email protected] value for salary: 16000old 2: values(&eno,'&ename','&address','&email',&salary)new 2: values(10,'bhavan','dhaisar','[email protected]',16000)

    1 row created.

    SQL> select * from employee2 ;

    ENO ENAME ADDRESS EMAIL SALARY---------- ---------- --------------- --------------- ----------

    1 anshu nsp [email protected] 10002 ravi mira road [email protected] 80003 shree bhynder [email protected] 150004 Bhavesh vasai [email protected] 35005 Jharna naigaon [email protected] 100006 karishma borivali [email protected] 110007 Ivan kandivali [email protected] 20008 shiv andheri [email protected] 130009 rashmi jogeshwari [email protected] 15000

    10 bhavan dhaisar [email protected] 16000

    10 rows selected.

  • SQL> connect scott/tiger @horiz as sysdbaConnected.

    SQL> create public database link link12 connect to scott identified by tigerusing 'horiz1' ;

    Database link created.

    SQL> connect scott/tiger @horizConnected.SQL> edWrote file afiedt.buf

    1* create table emp1 as select * from employee where salary /

    Table created.

    SQL> select * from emp12 ;

    ENO ENAME ADDRESS EMAIL SALARY---------- ---------- --------------- --------------- -----------------------------------

    1 anshu nsp [email protected] 10002 ravi mira road [email protected] 80003 shree bhynder [email protected] 150004 Bhavesh vasai [email protected] 35005 Jharna naigaon [email protected] 100006 karishma borivali [email protected] 110007 Ivan kandivali [email protected] 20008 shiv andheri [email protected] 130009 rashmi jogeshwari [email protected] 15000

    9 rows selected.

  • SQL> edWrote file afiedt.buf

    1* create table emp2 as select * from employee where salary>15000SQL> /

    Table created.

    SQL> select * from emp2;

    ENO ENAME ADDRESS EMAIL SALARY---------- ---------- --------------- --------------- ----------

    3 shree bhynder [email protected] 150004 Bhavesh vasai [email protected] 350005 Jharna naigaon [email protected] 1000007 Ivan kandivali [email protected] 200008 shiv andheri [email protected] 130009 rashmi jogeshwari [email protected] 150000

    10 Bhavan dahisar [email protected] 160000

    7 rows selected.

  • SQL> select eno,salary from emp1 union select eno,salary from emp2@link12;

    ENO SALARY---------- ----------

    1 100002 80003 150004 350005 1000006 110007 200008 130009 150000

    10 160000

    10 rows selected.

    SQL> edWrote file afiedt.buf

    1 select eno,email from emp1 where salary=15000 union2* select eno,email from emp2 @link12 where salary=15000

    SQL> /

    ENO EMAIL---------- ---------------

    3 [email protected]

  • SQL> edWrote file afiedt.buf

    1 select ename,email from emp1 where eno=8 union2* select ename,email from emp2 @link12 where eno=8

    SQL> /

    ENAME EMAIL---------- ---------------

    shiv [email protected]

    SQL> edWrote file afiedt.buf

    1 select ename,address from emp1 where eno=7 union2* select ename,address from emp2 @link12 where eno=7

    SQL> /

    ENAME ADDRESS---------- ---------------

    Ivan kandivali

  • PRACTICAL NO: 5SQL> connect scott/tiger @vertiConnected.SQL> create table employee(eno number(3),ename varchar2(10),addressvarchar2(15),2 email varchar2(15),salary number(10)) ;

    Table created.

    SQL> insert into employee(eno,ename,address,email,salary)2 values(&eno,'&ename','&address','&email',&salary);

    Enter value for eno: 1Enter value for ename: anshuEnter value for address: nspEnter value for email: [email protected] value for salary: 100000old 2: values(&eno,'&ename','&address','&email',&salary)new 2: values(1,'anshu','nsp','[email protected]',100000)

    1 row created.SQL> edWrote file afiedt.buf1 insert into employee(eno,ename,address,email,salary)2* values(&eno,'&ename','&address','&email',&salary)

    SQL> /Enter value for eno: 2Enter value for ename: raviEnter value for address: mira roadEnter value for email: [email protected] value for salary: 140000old 2: values(&eno,'&ename','&address','&email',&salary)new 2: values(2,'ravi','mira road','[email protected]',140000)

    1 row created.

  • SQL> edWrote file afiedt.buf

    1 insert into employee(eno,ename,address,email,salary)2* values(&eno,'&ename','&address','&email',&salary)

    SQL> /Enter value for eno: 3Enter value for ename: shreeEnter value for address: bhynderEnter value for email: [email protected] value for salary: 15000old 2: values(&eno,'&ename','&address','&email',&salary)new 2: values(3,'shree','bhynder','[email protected]',15000)

    1 row created.

    SQL> edWrote file afiedt.buf

    1 insert into employee(eno,ename,address,email,salary)2* values(&eno,'&ename','&address','&email',&salary)

    SQL> /Enter value for eno: 4Enter value for ename: BhaveshEnter value for address: vasaiEnter value for email: [email protected] value for salary: 35000old 2: values(&eno,'&ename','&address','&email',&salary)new 2: values(4,'Bhavesh','vasai','[email protected]',35000)

    1 row created.

  • SQL> edWrote file afiedt.buf

    1 insert into employee(eno,ename,address,email,salary)2* values(&eno,'&ename','&address','&email',&salary)

    SQL> /Enter value for eno: 5Enter value for ename: JharnaEnter value for address: naigaonEnter value for email: [email protected] value for salary: 10000old 2: values(&eno,'&ename','&address','&email',&salary)new 2: values(5,'Jharna','naigaon','[email protected]',10000)

    1 row created.

    SQL> edWrote file afiedt.buf

    1 insert into employee(eno,ename,address,email,salary)2* values(&eno,'&ename','&address','&email',&salary)

    SQL> /Enter value for eno: 6Enter value for ename: jarishmaEnter value for address: borivaliEnter value for email: [email protected] value for salary: 11000old 2: values(&eno,'&ename','&address','&email',&salary)new 2: values(6,'jarishma','borivali','[email protected]',11000)

    1 row created.

  • SQL> edWrote file afiedt.buf

    1 insert into employee(eno,ename,address,email,salary)2* values(&eno,'&ename','&address','&email',&salary)

    SQL> /Enter value for eno: 7Enter value for ename: IvanEnter value for address: kandivaliEnter value for email: [email protected] value for salary: 2000old 2: values(&eno,'&ename','&address','&email',&salary)new 2: values(7,'Ivan','kandivali','[email protected]',2000)

    1 row created.

    SQL> edWrote file afiedt.buf

    1 insert into employee(eno,ename,address,email,salary)2* values(&eno,'&ename','&address','&email',&salary)

    SQL> /Enter value for eno: 8Enter value for ename: shivEnter value for address: andheriEnter value for email: [email protected] value for salary: 1500000old 2: values(&eno,'&ename','&address','&email',&salary)new 2: values(8,'shiv','andheri','[email protected]',1500000)

    1 row created.

  • SQL> edWrote file afiedt.buf

    1 insert into employee(eno,ename,address,email,salary)2* values(&eno,'&ename','&address','&email',&salary)

    SQL> /Enter value for eno: 9Enter value for ename: rashmiEnter value for address: jogeshwariEnter value for email: [email protected] value for salary: 160000old 2: values(&eno,'&ename','&address','&email',&salary)new 2: values(9,'rashmi','jogeshwari','[email protected]',160000)

    1 row created.

    SQL> edWrote file afiedt.buf

    1 insert into employee(eno,ename,address,email,salary)2* values(&eno,'&ename','&address','&email',&salary)

    SQL> /Enter value for eno: 10Enter value for ename: BhavanEnter value for address: dahisarEnter value for email: [email protected] value for salary: 16000old 2: values(&eno,'&ename','&address','&email',&salary)new 2: values(10,'Bhavan','dahisar','[email protected]',16000)

    1 row created.

  • SQL> select * from employee;

    ENO ENAME ADDRESS EMAIL SALARY---------- ---------- --------------- --------------- ----------

    1 anshu nsp [email protected] 1000002 ravi mira road [email protected] 1400003 shree bhynder [email protected] 150004 Bhavesh vasai [email protected] 350005 Jharna naigaon [email protected] 100006 jarishma borivali [email protected] 110007 Ivan kandivali [email protected] 20008 shiv andheri [email protected] 15000009 rashmi jogeshwari [email protected] 160000

    10 Bhavan dahisar [email protected] 16000

    10 rows selected.

    SQL> connect scott/tiger @verti1 as sysdbaConnected.SQL> create public database link a1 connect to scott identified by tiger2 using 'verti';

    Database link created.

    SQL> connect scott/tiger @verti;Connected.SQL> create table emp1 as select eno,ename,address from employee;

    Table created.

  • SQL> select * from emp1;

    ENO ENAME ADDRESS---------- ---------- ---------------

    1 anshu nsp2 ravi mira road3 shree bhynder4 Bhavesh vasai5 Jharna naigaon6 jarishma borivali7 Ivan kandivali8 shiv andheri9 rashmi jogeshwari

    10 Bhavan dahisar

    10 rows selected.

    SQL> connect scott/tiger @verti1;Connected.SQL> edWrote file afiedt.buf

    1* create table emp2 as select eno,email,salary from employee @a1SQL> /

    Table created.

  • SQL> select * from emp2;

    ENO EMAIL SALARY---------- --------------- ----------

    1 [email protected] 1000002 [email protected] 1400003 [email protected] 150004 [email protected] 350005 [email protected] 100006 [email protected] 110007 [email protected] 20008 [email protected] 15000009 [email protected] 160000

    10 [email protected] 16000

    10 rows selected.

    SQL> select emp1.eno,emp2.salary from emp2,emp1 @a12 where emp1.eno=5 and emp1.eno=emp2.eno;

    ENO SALARY---------- ----------

    5 10000

    SQL> select emp1.eno,emp2.email from emp2,emp1 @a12 where emp1.ename='anshu' and emp1.eno=emp2.eno3 ;

    ENO EMAIL---------- ---------------

    1 [email protected]

  • SQL> select emp1.ename,emp2.email from emp2 , emp1 @a12 where emp1.eno=3 and emp1.eno=emp2.eno;

    ENAME EMAIL---------- ---------------

    shree [email protected]

    SQL> select emp1.ename,emp2.salary from emp2 , emp1 @a12 where emp1.eno=emp2.eno and emp2.salary>20003 ;

    ENAME SALARY---------- ----------

    anshu 100000ravi 140000shree 15000Bhavesh 35000Jharna 10000jarishma 11000shiv 1500000rashmi 160000Bhavan 16000

    9 rows selected.

  • PRACTICAL NO: 6

    Create different Types and Tables

    SQL> create table emp_xml15(2 dept_id number(4),3 employee_spec XMLtype);

    Table created.

    Insertion of different values in the tables

    Table Name1: emp_xml15Format : emp_xml15 (dept_id, employee_spec)

    SQL> insert into emp_xml15 values(1,XMLtype(2 '3 sharmila 4 [email protected] 234566 [email protected] 12/12/20038 '));

    1 row created.SQL> insert into emp_xml15 values(1,XMLtype(2 '3 anita 4 [email protected] 2343466 [email protected] 2/6/20038 '));

    1 row created.

  • SQL> insert into emp_xml15 values(1,XMLtype(2 '3 ekta 4 [email protected] 23434566 [email protected] 24/5/20018 '));

    1 row created.

    SQL> insert into emp_xml15 values(1,XMLtype(2 '3 nancy 4 [email protected] 23436786 [email protected] 21/5/20028 '));

    1 row created.

    SQL> insert into emp_xml15 values(1,XMLtype(2 '3 falguni 4 [email protected] 23433456 [email protected] 1/8/20028 '));

    1 row created.

  • SQL> insert into emp_xml15 values(1,XMLtype(2 '3 sweta 4 [email protected] 23438906 [email protected] 2/1/20018 '));

    1 row created.

    SQL> insert into emp_xml15 values(2,XMLtype(2 '3 aarti 4 [email protected] 234338986 [email protected] 4/9/20028 '));

    1 row created.

    SQL> insert into emp_xml15 values(2,XMLtype(2 '3 sandy 4 [email protected] 235678986 [email protected] 4/4/20048 '));

    1 row created.

  • Firing queries on the created tables

    a) Retrieve the names of employee:

    SQL> select e.employee_spec.extract('//name/text()').getStringVal()"EMP_NAME" from emp_xml15 e;

    Output:

    EMP_NAME--------------------------------------------------------------------------------

    sharmilaanitaektanancyfalguniswetaaartisandy

    8 rows selected.

    b) Retrieve the acc_no of employees:

    SQL>select e.employee_spec.extract('//acc_no/text()').getStringVal()2* "Acc_No" from emp_xml15 e;

    Output:

    Acc_No------------------------------------------------------------------------------

    2345623434623434562343678

  • 2343345234389023433898235678988 rows selected.

    c) Retrieve the names, acc_no, email of employees:

    SQL> select e.employee_spec.extract('//name/text()').getStringVal()2 "NAME",e.employee_spec.extract('//acc_no/text()').getStringVal()3 "ACC_NO",e.employee_spec.extract('//email/text()').getStringVal()4 "EMAIL" from emp_xml15 e5 /

    Output:

    NAME ACC_NO EMAIL--------------------------------------------------------------------------------

    sharmila 23456 [email protected] 234346 [email protected] 2343456 [email protected] 2343678 [email protected] 2343345 [email protected] 2343890 [email protected] 23433898 [email protected] 23567898 [email protected]

    8 rows selected.

  • d) Update the 3rd record from the table and display the name of an employee:

    SQL> update emp_xml15 e set employee_spec=XMLtype('2 ekta 3 [email protected] 23434565 [email protected] 24/5/20017 This is the updated record8 ')9 where10 e.employee_spec.extract('//name/text()').getStringVal()11 ='ekta' ;

    1 row updated.

    SQL> select e.employee_spec.extract('//name/text()').getStringVal()"NAME",2 e.employee_spec.getClobVal() "EMP_SPECIFICATION"3 from emp_xml15 e where4 e.employee_spec.extract('//name/text()').getStringVal()='ekta ' ;

    Output:NAME-------------------------------------------------------------------------------

    EMP_SPECIFICATION-------------------------------------------------------------------------------

    ekta

    ekta [email protected]@hotmail.com24/5/2001This is the updated record

  • e) Delete the 4th record from the table:

    SQL> delete from emp_xml15 e2 where e.employee_spec.extract('//name/text()').getStringVal()3 ='nancy ';

    1 row deleted.

    SQL> select e.employee_spec.extract('//name/text()').getStringVal() "NAME"from emp_xml151 e;

    Output:

    NAME--------------------------------------------------------------------------------

    sharmilaanitaektafalguniswetaaarti

    6 rows selected.

  • PRACTICAL NO: 7-A

    SQL> create table customer2 (3 cust_name varchar(10),4 customer_no number(5),5 open_date timestamp(2),6 transac_time timestamp(2)7 )8 ;

    Table created.

    SQL> insert into customer values('keyur',1,'12-aug-2011 1.00.00.000000pm','14-sep-2012 10.00 am');

    1 row created.

    SQL> insert into customer values('shlok',2,'18-feb-1983 8.45.00.000000pm','14-jan-2011 9.23.01 am');

    1 row created.

    SQL> insert into customer values('shruti',2023,'16-jan-2000 10.30.00.000000am','10-june-2004 3.30 pm');

    1 row created.

  • SQL> insert into customer values('dhara',2002,'23-feb-1992 5.30.00.000000pm','13-dec-2006 12.00 pm');

    1 row created.

    SQL> insert into customer values('akash',2012,'24-sep-2002 4.30.00.000000pm','12-july-2005 9.30 am');

    1 row created.

    SQL> select * from customer;

    CUST_NAME CUSTOMER_NO---------- -----------

    OPEN_DATE---------------------------------------------------------------------------

    TRANSAC_TIME---------------------------------------------------------------------------

    keyur 112-AUG-11 01.00.00.00 PM14-SEP-20 12.10.00.00 AM

    shlok 218-FEB-83 08.45.00.00 PM14-JAN-20 11.09.23.01 AM

  • CUST_NAME CUSTOMER_NO---------- -----------

    OPEN_DATE---------------------------------------------------------------------------

    TRANSAC_TIME---------------------------------------------------------------------------

    shruti 202316-JAN-00 10.30.00.00 AM10-JUN-20 04.03.30.00 PM

    dhara 200223-FEB-92 05.30.00.00 PM

    CUST_NAME CUSTOMER_NO---------- -----------

    OPEN_DATE---------------------------------------------------------------------------

    TRANSAC_TIME---------------------------------------------------------------------------

    13-DEC-20 06.12.00.00 PM

    akash 201224-SEP-02 04.30.00.00 PM12-JUL-20 05.09.30.00 AM

    SQL> select * from customer where to_char(open_date,'HH.MI AM')2 LIKE '10.30 am'3 ;

    no rows selected

  • SQL> select * from customer where to_char(open_date,'hh.mi am') like '10.30am';

    CUST_NAME CUSTOMER_NO---------- -----------

    OPEN_DATE---------------------------------------------------------------------------

    TRANSAC_TIME---------------------------------------------------------------------------

    shruti 202316-JAN-00 10.30.00.00 AM10-JUN-20 04.03.30.00 PM

    SQL> select * from customer where to_char(transac_time,'hh.mi am') like'8.46 pm';

    no rows selected

    SQL> select * from customer where to_char(transac_time,'hh.mi pm') like'8.46 pm';

    no rows selected

    SQL> select * from customer where to_char(open_date,'dd-mm-yyyy hh.miam') like '27-10-1999 11.30 am;

    no rows selected

  • SQL> select * from customer where to_char(open_date,'dd')='18';

    CUST_NAME CUSTOMER_NO---------- -----------

    OPEN_DATE---------------------------------------------------------------------------

    TRANSAC_TIME---------------------------------------------------------------------------

    shlok 218-FEB-83 08.45.00.00 PM14-JAN-20 11.09.23.01 AM

    SQL> select * from customer where to_char(open_date,'yy')='92';

    CUST_NAME CUSTOMER_NO---------- -----------

    OPEN_DATE---------------------------------------------------------------------------

    TRANSAC_TIME---------------------------------------------------------------------------

    dhara 200223-FEB-92 05.30.00.00 PM13-DEC-20 06.12.00.00 PM

    SQL> select count(open_date) from customer whereto_char(open_date,'mm')='02';

    COUNT(OPEN_DATE)----------------

    2

  • PRACTICAL NO: 7-B

    Table definition :

    SQL> Create table tbl_shares152 (3 cname varchar2(20),4 nofshares number(5),5 pricepshare number(5),6 transtime timestamp(6)7 );

    Table created.

    Insertion of different values in the tables

    Table Name: tbl_shares15Format : tbl_shares(cname, noofshares, pricepshare , transtime)

    SQL> insert into tbl_shares15 values(RelianceInfocom,250,25,systimestamp);

    1 row created.

    SQL> insert into tbl_shares15 values('Tata',205,20,'05-jun-04 11.45.00.000000am');

    1 row created.

    SQL> insert into tbl_shares15 values('Wipro',250,25,'10-mar-0306.15.00.000000

    pm');

    1 row created.

  • SQL> insert into tbl_shares15 values('Patni',115,15,'08-may-0107.25.00.000000

    am');

    1 row created.

    SQL> insert into tbl_shares15 values('TCS',140,12,'14-apr-05 05.30.00.000000pm');

    1 row created.

    SQL> insert into tbl_shares15 values('Google',310,30,'12-sep-0310.30.00.000000

    am');

    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:

    CNAME NOFSHARES PRICEPSHARE TRANSTIME------------- ---------------------- ---------------------- --------------------

    Infosys 110 10 01-JAN-0304.00.00.000000 PMTata 205 20 05-JUN-0411.45.00.000000 AMWipro 250 25 10-MAR-0306.15.00.000000 PMPatni 115 15 08-MAY-0107.25.00.000000 AMTCS 140 12 14-APR-0505.30.00.000000 PMGoogle 310 30 12-SEP-0310.30.00.000000 AMHero Honda 100 250 21-AUG-0405.30.00.000000 PM

    5 rows selected.

    QUERIES :

    1) Find all the names of a company whose share price is more than Rs.100 at11:45 A.M.

    SQL> select cname from tbl_shares152 where pricepshare>153 and to_char(transtime,'HH12:MI:AM')='11:45:AM'

    SQL> /Output:cname

    --------------------

    Tata

  • 2) Find the name of company which has highest shares price at 5.00 P.M.

    SQL> select cname from tbl_shares15 where pricepshare in2 (select max(pricepshare) from tbl_shares153 where to_char(transtime,'HH12:MI:AM')='05:30:PM')

    SQL> /

    Output:

    cname

    --------------------

    Hero Honda

  • PRACTICAL NO: 8

    Create different Types and Tables

    SQL> create table Empl(eno number(8) primary key,ename varchar(20),hrs number(8),pno number(8),super_no number(8) CONSTRAINT sup UNIQUE);

    Table created.

    SQL> create table project(pno number(8) primary key,pname varchar(20),thrs number(8),super_no number(8) CONSTRAINT supfk references empl(super_no));

    Table created.

    Insertion of different values in the tables

    Table Name1: EmplFormat : Empl(eno, ename, hrs, pno , super_no)

    SQL> insert into Empl values(1,'ekta',7,10,1001);

    1 row created.

    SQL> insert into Empl values(2,'sweta',5,20,1002);

    1 row created.

  • SQL> insert into Empl values(3,'sharmila',3,10,1003);

    1 row created.

    SQL> insert into Empl values(4,'anita',1,20,1004);

    1 row created.

    SQL> insert into Empl values(5,'sandeep',5,30,1005);

    1 row created.

    SQL> insert into Empl values(6,'gautam',8,40,1006);

    1 row created.

    SQL> insert into Empl values(7,'akshay',3,30,1007);

    1 row created.

    SQL>insert into Empl values(8,'sagar',12,40,1008);

    1 row created.

    SQL> insert into Empl values(9,'aarti',1,10,1009);

    1 row created.

    SQL> insert into Empl values(10,'bhakti',9,20,1010);

    1 row created.

    Table Name2: ProjectFormat : Project(pno, pname, thrs ,super_no)

    SQL> insert into project values(10,'distributed',10,1001);1 row created.

  • SQL> insert into project values(20,'parallel',6,1002);1 row created.

    SQL> insert into project values(30,'active',5,1005);1 row created.

    SQL> insert into project values(40,'temporal',5,1008);1 row created.

    Firing queries on the created tables

    Create trigger according to events specified.

    a) Creating a trigger to insert new employee tuple and display the newtotal hours from project table.

    Event1: Insert a new employee tupleEvent: New Employee is assigned to a projectCondition: pno value is not Null when emp is assigned to a projectAction: update the total thrs of project by adding hrs to old thrs.

    Trigger:

    SQL> create or replace Trigger thrsafter insert on Emplfor each rowwhen(New.pno IS NOT NULL)begin

    update projectset thrs=thrs + :New.hrswhere pno=:New.pno;

    end;

    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 empltable*/SQL> insert into Empl values(11,'nancy',4,30,1011);

    1 row created.

    Output:

    SQL> select * from project;

    PNO PNAME THRS SUPER_NO---------- ------------------- ---------- -----------------

    10 distributed 10 100120 parallel 6 100230 active 9 100540 temporal 5 1008

    b) Creating a trigger to change the hrs of existing employee and displaythe new total hours from project table.

    Event2: Changing the hrs of existing employee.Event: employee is assigned new hrsCondition: pno value is not NULL when emp is assigned new hrs.Action: update thrs of project by adding hrs to thrs & subtract old hrs

    from it.Trigger:

    SQL> create Trigger thrs1after update of hrs on Emplfor each rowwhen(New.pno IS NOT NULL)beginupdate projectset thrs=thrs+:New.hrs-:Old.hrswhere pno=:New.pno;end;

    Trigger created.

  • SQL> update Emplset hrs=10where eno=11;

    1 row updated.

    Ouput:

    SQL> select * from project;

    PNO PNAME THRS SUPER_NO---------- ------------------- ---------- -----------------

    10 distributed 10 100120 parallel 6 100230 active 15 100540 temporal 5 1008

    C) Creating a trigger to change the project of an employee and display thenew total hours from project table.

    Event3: Changing the project of an employee.Event: Change of ProjectCondition: No condition

    Action: update the thrs of new project by adding new hrs & subtract oldhrs from thrs from old project.Trigger:

    SQL> create Trigger thrs2after update of pno on Emplfor each rowwhen(New.pno IS NOT NULL)beginupdate projectset thrs=thrs+:New.hrs-:Old.hrswhere pno=:New.pno;end;

    Trigger created.

  • SQL> update Emplset pno=10where eno=2;

    1 row updated.

    SQL> update Emplset pno=20where eno=7;

    1 row updated.

    Output:

    Same output for 2 update:

    SQL> select * from project;

    PNO PNAME THRS SUPER_NO---------- ------------------- ---------- -----------------

    10 distributed 10 100120 parallel 6 100230 active 15 100540 temporal 5 1008

    d) Creating a trigger to delete the project of an employee.

    Event4: Deleting 1 or more project of an employee.Event: Deleting the project.Condition: OLD.pno is not NULL.Action: update the thrs by subtracting old hrs.

    Trigger:

  • SQL> create trigger thrs4after delete on Emplfor each rowwhen(OLD.pno IS NOT NULL)beginupdate projectset thrs=thrs-:OLD.hrswhere pno=:OLD.pno;end;

    Trigger created.

    SQL> delete from Empl where eno=11;

    1 row deleted.

    SQL> select * from project;

    PNO PNAME THRS SUPER_NO---------- ------------------- ---------- -----------------

    10 distributed 10 100120 parallel 6 100230 active 5 100540 temporal 5 1008

  • PRACTICAL NO: 9

    Create different Types and Tables

    SQL> create table Empl(eno number(8) primary key,ename varchar(20),hrs number(8),pno number(8),super_no number(8) CONSTRAINT sup UNIQUE);

    Table created.

    SQL> create table project(pno number(8) primary key,pname varchar(20),thrs number(8),super_no number(8) CONSTRAINT supfk references empl(super_no));

    Table created.

    Insertion of different values in the tables

    Table Name1: EmplFormat : Empl(eno, ename, hrs, pno , super_no)

    SQL> insert into Empl values(1,'ekta',7,10,1001);

    1 row created.

    SQL> insert into Empl values(2,'sweta',5,20,1002);

    1 row created.

  • SQL> insert into Empl values(3,'sharmila',3,10,1003);

    1 row created.

    SQL> insert into Empl values(4,'anita',1,20,1004);

    1 row created.

    SQL> insert into Empl values(5,'sandeep',5,30,1005);

    1 row created.

    SQL> insert into Empl values(6,'gautam',8,40,1006);

    1 row created.

    SQL> insert into Empl values(7,'akshay',3,30,1007);

    1 row created.

    SQL>insert into Empl values(8,'sagar',12,40,1008);

    1 row created.

    SQL> insert into Empl values(9,'aarti',1,10,1009);

    1 row created.

    SQL> insert into Empl values(10,'bhakti',9,20,1010);

    1 row created.

    Table Name2: ProjectFormat : Project(pno, pname, thrs ,super_no)

    SQL> insert into project values(10,'distributed',10,1001);1 row created.

  • SQL> insert into project values(20,'parallel',6,1002);1 row created.

    SQL> insert into project values(30,'active',5,1005);1 row created.

    SQL> insert into project values(40,'temporal',5,1008);1 row created.

    Firing queries on the created tables

    SQL> select * from Empl where pno=10;

    ENO ENAME HRS PNO SUPER_NO---------- ---------- --------------- --------------- -----------------------------------

    1 ekta 7 10 10013 sharmila 3 10 10039 aarti 1 10 1009

  • Create trigger according to events specified.

    a) Creating a trigger to increase hours of all employees working on theproject number 10 by 2.

    Event1: Changing the hrs of existing employee.Event: Employee is assigned new hrsCondition: pno value is not NULL when emp is assigned new hrs.Action: Update thrs of employees working on project number 10 by 2

    Trigger:

    SQL> create Trigger thrsafter update of hrs on Emplfor each statementwhen(New.pno IS NOT NULL)beginupdate Emplset hrs=:hrs+2;where pno=10;end;

    Trigger created.

    SQL> select * from Empl where pno=10;

    ENO ENAME HRS PNO SUPER_NO---------- ---------- --------------- --------------- -----------------------------------

    1 ekta 9 10 10013 sharmila 5 10 10039 aarti 3 10 1009

  • PRACTICAL NO: 10

    SQL> create table university_15 (2 mkt_id number primary key,3 name varchar2(32),4 shape mdsys.sdo_geometry);

    Table created.

    SQL> insert into university_15 values(2 1,3 'abc',4 mdsys.sdo_geometry(5 2003, -- 2-dimensional polygon6 null,7 null,8 mdsys.sdo_elem_info_array(1,1003,3), -- one rectangle (1003 =exterior)9 mdsys.sdo_ordinate_array(1,1, 5,7)10 -- only 2 points needed to11 -- define rectangle (lower left and upper right) with12 -- cartesian-coordinate data13 )14 );

    1 row created.

    SQL> insert into university_15 values(1 2,2 'pqr',3 mdsys.sdo_geometry(4 2003, -- 2-dimensional polygon5 null,6 null,7 mdsys.sdo_elem_info_array(1,1003,1),

  • 8 -- one polygon (exterior polygon ring)9 mdsys.sdo_ordinate_array(5,1, 8,1, 8,6, 5,7, 5,1)10 )11 );

    1 row created.

    insert into university_15 values(1 3,2 'mno',3 mdsys.sdo_geometry(4 2003, -- 2-dimensional polygon5 null,6 null,7 mdsys.sdo_elem_info_array(1,1003,1),8 -- one polygon (exterior polygon ring)9 mdsys.sdo_ordinate_array(3,3, 6,3, 6,5, 4,5, 3,3)10 )11 );

    1 row created.

    SQL>insert into university_15 values(1 4,2 xyz,3 mdsys.sdo_geometry(4 2003, -- 2-dimensional polygon5 null,6 null,7 mdsys.sdo_elem_info_array(1,1003,4), -- one circle8 mdsys.sdo_ordinate_array(8,7, 10,9, 8,11)9 )10 );

    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 -- srid8 );

    1 row created.

    SQL > create index university_spatial_idxon university_15(shape)indextype is mdsys.spatial_index;

    Index created.

    1) Find the topological intersection of two geometries.

    SQL> select sdo_geom.sdo_intersection(c_a.shape, c_c.shape, 0.005)from university_15 c_a, university_15 c_cwhere c_a.name = 'abc' and c_c.name = 'mno';

    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_ARRAY(4, 5, 3, 3, 5, 3, 5, 5, 4, 5))

  • 2) Find whether two geometric figures are equivalent to each other.

    SQL>select sdo_geom.relate(c_b.shape, 'anyinteract', c_d.shape, 0.005)from university_15 c_b, university_15 c_dwhere c_b.name = 'pqr' and c_d.name = 'xyz';

    Output:

    SDO_GEOM.RELATE(C_B.SHAPE,'ANYINTERACT',C_D.SHAPE,0.005)--------------------------------------------------------------------------------

    FALSE

    SQL>select sdo_geom.relate(c_b.shape, 'anyinteract', c_a.shape, 0.005)from university_15 c_b, university_15 c_awhere c_b.name = 'pqr' and c_a.name = 'abc';

    Output:

    SDO_GEOM.RELATE(C_B.SHAPE,'ANYINTERACT',C_A.SHAPE,0.005)--------------------------------------------------------------------------------

    TRUE

    3) Find the areas of all direction locations.

    SQL>select name, sdo_geom.sdo_area(shape, 0.005) from university_15;

    Output:

    NAME SDO_GEOM.SDO_AREA(SHAPE,0.005)-------------------------------- ------------------------------

    abc 24pqr 16.5mno 5xyz 12.5663706

  • 4) Find the area of only one location abc.

    SQL>select c.name, sdo_geom.sdo_area(c.shape, 0.005) from university_15 cwhere c.name = 'abc';

    Output:

    NAME SDO_GEOM.SDO_AREA(C.SHAPE,0.005)-------------------------------- --------------------------------

    abc 24

    5) Find the distance between two geometries.

    SQL>select sdo_geom.sdo_distance(c_b.shape, c_d.shape, 0.005)from university_15 c_b, university_15 c_dwhere c_b.name = 'pqr' and c_d.name = 'xyz';

    Output:

    SDO_GEOM.SDO_DISTANCE(C_B.SHAPE,C_D.SHAPE,0.005)------------------------------------------------

    .846049894

    ADBMSPracIndex.pdfPractical1.pdfPractical2.pdfPractical3.pdfPractical4.pdfPractical5.pdfPractical6.pdfPractical7A.pdfPractical7B.pdfPractical8.pdfPractical9.pdfPractical10.pdf