Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
3 views9 pages

New Text Document 3

The document outlines the creation of various SQL object types for managing book-related data, including AddressType, BranchType, AuthorType, and PublisherType. It also details the creation of two tables, 'books' and 'library', and shows multiple insertions of book records along with their authors and publishers. Finally, it includes SQL queries to retrieve information about books and their authors from the database.

Uploaded by

susxsusan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views9 pages

New Text Document 3

The document outlines the creation of various SQL object types for managing book-related data, including AddressType, BranchType, AuthorType, and PublisherType. It also details the creation of two tables, 'books' and 'library', and shows multiple insertions of book records along with their authors and publishers. Finally, it includes SQL queries to retrieve information about books and their authors from the database.

Uploaded by

susxsusan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 9

SQL> CREATE TYPE AddressType AS OBJECT (txbga

2 pincode NUMBER(6),
3 street VARCHAR2(20),
4 city VARCHAR2(30),
5 state VARCHAR2(30)
6 );
7 /

Type created.

SQL> CREATE TYPE BranchType AS OBJECT (


2 address AddressType,
3 phone INTEGER
4 );
5 /

Type created.

SQL> CREATE TYPE AuthorType AS OBJECT (


2 name VARCHAR2(50),
3 address AddressType
4 );
5 /

Type created.

SQL> CREATE TYPE PublisherType AS OBJECT (


2 name VARCHAR2(50),
3 address AddressType,
4 branches BranchType
5 );
6 /

Type created.

SQL> CREATE TABLE books (


2 title VARCHAR2(50),
3 publisher PublisherType,
4 author AuthorType
5 );

Table created.

SQL> CREATE TABLE library (


2 libraryName VARCHAR2(50),
3 books VARCHAR2(50),
4 address AddressType,
5 author AuthorType
6 );

Table created.

SQL> INSERT INTO books VALUES (


2 'Harry Potter',
3 PublisherType(
4 'Bloomsbury',
5 AddressType(560001, 'King St', 'London', 'England'),
6 BranchType(AddressType(560002, 'Queen Rd', 'London', 'England'),
1234567890)
7 ),
8 AuthorType('J.K. Rowling', AddressType(560001, 'King St', 'London',
'England'))
9 );

1 row created.

SQL> INSERT INTO books VALUES (


2 'The Hobbit',
3 PublisherType(
4 'Allen & Unwin',
5 AddressType(400001, 'Shire Rd', 'Wellington', 'NZ'),
6 BranchType(AddressType(400002, 'Ring St', 'Wellington', 'NZ'),
2345678901)
7 ),
8 AuthorType('J.R.R. Tolkien', AddressType(400001, 'Shire Rd', 'Wellington',
'NZ'))
9 );
Enter value for unwin:
old 4: 'Allen & Unwin',
new 4: 'Allen ',

1 row created.

SQL> INSERT INTO books VALUES (


2 '1984',
3 PublisherType(
4 'Secker & Warburg',
5 AddressType(110001, 'Dystopia Ave', 'London', 'England'),
6 BranchType(AddressType(110002, 'Orwell St', 'London', 'England'),
3456789012)
7 ),
8 AuthorType('George Orwell', AddressType(110001, 'Dystopia Ave', 'London',
'England'))
9 );
Enter value for warburg:
old 4: 'Secker & Warburg',
new 4: 'Secker ',

1 row created.

SQL> INSERT INTO books VALUES (


2 'To Kill a Mockingbird',
3 PublisherType(
4 'J.B. Lippincott',
5 AddressType(411001, 'Mockingbird Ln', 'Monroeville', 'USA'),
6 BranchType(AddressType(411002, 'Harper Rd', 'Monroeville', 'USA'),
4567890123)
7 ),
8 AuthorType('Harper Lee', AddressType(411001, 'Mockingbird Ln',
'Monroeville', 'USA'))
9 );

1 row created.

SQL>
SQL> INSERT INTO books VALUES (
2 'The Alchemist',
3 PublisherType(
4 'HarperCollins',
5 AddressType(600001, 'Dream Rd', 'Rio', 'Brazil'),
6 BranchType(AddressType(600002, 'Soul St', 'Rio', 'Brazil'),
5678901234)
7 ),
8 AuthorType('Paulo Coelho', AddressType(600001, 'Dream Rd', 'Rio',
'Brazil'))
9 );

1 row created.

SQL>
SQL> INSERT INTO books VALUES (
2 'The Great Gatsby',
3 PublisherType(
4 'Scribner',
5 AddressType(100001, 'Jazz St', 'NYC', 'USA'),
6 BranchType(AddressType(100002, 'Light Rd', 'NYC', 'USA'), 6789012345)
7 ),
8 AuthorType('F. Scott Fitzgerald', AddressType(100001, 'Jazz St', 'NYC',
'USA'))
9 );

1 row created.

SQL>
SQL> INSERT INTO books VALUES (
2 'Pride and Prejudice',
3 PublisherType(
4 'T. Egerton',
5 AddressType(201001, 'Love Rd', 'Steventon', 'England'),
6 BranchType(AddressType(201002, 'Darcy Ln', 'Steventon', 'England'),
7890123456)
7 ),
8 AuthorType('Jane Austen', AddressType(201001, 'Love Rd', 'Steventon',
'England'))
9 );

1 row created.

SQL>
SQL> INSERT INTO books VALUES (
2 'The Catcher in the Rye',
3 PublisherType(
4 'Little, Brown and Company',
5 AddressType(700001, 'Holden Ave', 'NYC', 'USA'),
6 BranchType(AddressType(700002, 'Phoebe Rd', 'NYC', 'USA'), 8901234567)
7 ),
8 AuthorType('J.D. Salinger', AddressType(700001, 'Holden Ave', 'NYC',
'USA'))
9 );

1 row created.

SQL>
SQL> INSERT INTO books VALUES (
2 'The Book Thief',
3 PublisherType(
4 'Picador',
5 AddressType(302001, 'Thief Rd', 'Sydney', 'Australia'),
6 BranchType(AddressType(302002, 'Words St', 'Sydney', 'Australia'),
9012345678)
7 ),
8 AuthorType('Markus Zusak', AddressType(302001, 'Thief Rd', 'Sydney',
'Australia'))
9 );

1 row created.

SQL>
SQL> INSERT INTO books VALUES (
2 'Life of Pi',
3 PublisherType(
4 'Canongate Books',
5 AddressType(605001, 'Ocean Rd', 'Pondicherry', 'India'),
6 BranchType(AddressType(605002, 'Tiger St', 'Pondicherry', 'India'),
9123456789)
7 ),
8 AuthorType('Yann Martel', AddressType(605001, 'Ocean Rd', 'Pondicherry',
'India'))
9 );

1 row created.

SQL> INSERT INTO library VALUES (


2 'Central Library',
3 'Harry Potter',
4 AddressType(560001, 'King St', 'London', 'England'),
5 AuthorType('J.K. Rowling', AddressType(560001, 'King St', 'London',
'England'))
6 );

1 row created.

SQL>
SQL> INSERT INTO library VALUES (
2 'City Library',
3 'The Hobbit',
4 AddressType(400001, 'Shire Rd', 'Wellington', 'NZ'),
5 AuthorType('J.R.R. Tolkien', AddressType(400001, 'Shire Rd', 'Wellington',
'NZ'))
6 );

1 row created.

SQL>
SQL> INSERT INTO library VALUES (
2 'Metro Library',
3 '1984',
4 AddressType(110001, 'Dystopia Ave', 'London', 'England'),
5 AuthorType('George Orwell', AddressType(110001, 'Dystopia Ave', 'London',
'England'))
6 );

1 row created.

SQL>
SQL> INSERT INTO library VALUES (
2 'Public Library',
3 'To Kill a Mockingbird',
4 AddressType(411001, 'Mockingbird Ln', 'Monroeville', 'USA'),
5 AuthorType('Harper Lee', AddressType(411001, 'Mockingbird Ln',
'Monroeville', 'USA'))
6 );

1 row created.

SQL>
SQL> INSERT INTO library VALUES (
2 'Readers Hub',
3 'The Alchemist',
4 AddressType(600001, 'Dream Rd', 'Rio', 'Brazil'),
5 AuthorType('Paulo Coelho', AddressType(600001, 'Dream Rd', 'Rio',
'Brazil'))
6 );

1 row created.

SQL>
SQL> INSERT INTO library VALUES (
2 'LitZone',
3 'The Great Gatsby',
4 AddressType(100001, 'Jazz St', 'NYC', 'USA'),
5 AuthorType('F. Scott Fitzgerald', AddressType(100001, 'Jazz St', 'NYC',
'USA'))
6 );

1 row created.

SQL>
SQL> INSERT INTO library VALUES (
2 'Classic Reads',
3 'Pride and Prejudice',
4 AddressType(201001, 'Love Rd', 'Steventon', 'England'),
5 AuthorType('Jane Austen', AddressType(201001, 'Love Rd', 'Steventon',
'England'))
6 );

1 row created.

SQL>
SQL> INSERT INTO library VALUES (
2 'Youth Library',
3 'The Catcher in the Rye',
4 AddressType(700001, 'Holden Ave', 'NYC', 'USA'),
5 AuthorType('J.D. Salinger', AddressType(700001, 'Holden Ave', 'NYC',
'USA'))
6 );

1 row created.

SQL>
SQL> INSERT INTO library VALUES (
2 'Global Library',
3 'The Book Thief',
4 AddressType(302001, 'Thief Rd', 'Sydney', 'Australia'),
5 AuthorType('Markus Zusak', AddressType(302001, 'Thief Rd', 'Sydney',
'Australia'))
6 );

1 row created.

SQL>
SQL> INSERT INTO library VALUES (
2 'Seaside Library',
3 'Life of Pi',
4 AddressType(605001, 'Ocean Rd', 'Pondicherry', 'India'),
5 AuthorType('Yann Martel', AddressType(605001, 'Ocean Rd', 'Pondicherry',
'India'))
6 );

1 row created.

SQL> SELECT
2 l.libraryName,
3 l.books AS bookTitle,
4 b.author.name AS authorName,
5 b.publisher.name AS publisherName
6 FROM
7 library l
8 JOIN
9 books b ON l.books = b.title;

LIBRARYNAME
--------------------------------------------------
BOOKTITLE
--------------------------------------------------
AUTHORNAME
--------------------------------------------------
PUBLISHERNAME
--------------------------------------------------
Metro Library
1984
George Orwell
Secker

LIBRARYNAME
--------------------------------------------------
BOOKTITLE
--------------------------------------------------
AUTHORNAME
--------------------------------------------------
PUBLISHERNAME
--------------------------------------------------
Central Library
Harry Potter
J.K. Rowling
Bloomsbury

LIBRARYNAME
--------------------------------------------------
BOOKTITLE
--------------------------------------------------
AUTHORNAME
--------------------------------------------------
PUBLISHERNAME
--------------------------------------------------
Seaside Library
Life of Pi
Yann Martel
Canongate Books

LIBRARYNAME
--------------------------------------------------
BOOKTITLE
--------------------------------------------------
AUTHORNAME
--------------------------------------------------
PUBLISHERNAME
--------------------------------------------------
Classic Reads
Pride and Prejudice
Jane Austen
T. Egerton

LIBRARYNAME
--------------------------------------------------
BOOKTITLE
--------------------------------------------------
AUTHORNAME
--------------------------------------------------
PUBLISHERNAME
--------------------------------------------------
Readers Hub
The Alchemist
Paulo Coelho
HarperCollins

LIBRARYNAME
--------------------------------------------------
BOOKTITLE
--------------------------------------------------
AUTHORNAME
--------------------------------------------------
PUBLISHERNAME
--------------------------------------------------
Global Library
The Book Thief
Markus Zusak
Picador

LIBRARYNAME
--------------------------------------------------
BOOKTITLE
--------------------------------------------------
AUTHORNAME
--------------------------------------------------
PUBLISHERNAME
--------------------------------------------------
Youth Library
The Catcher in the Rye
J.D. Salinger
Little, Brown and Company

LIBRARYNAME
--------------------------------------------------
BOOKTITLE
--------------------------------------------------
AUTHORNAME
--------------------------------------------------
PUBLISHERNAME
--------------------------------------------------
LitZone
The Great Gatsby
F. Scott Fitzgerald
Scribner

LIBRARYNAME
--------------------------------------------------
BOOKTITLE
--------------------------------------------------
AUTHORNAME
--------------------------------------------------
PUBLISHERNAME
--------------------------------------------------
City Library
The Hobbit
J.R.R. Tolkien
Allen

LIBRARYNAME
--------------------------------------------------
BOOKTITLE
--------------------------------------------------
AUTHORNAME
--------------------------------------------------
PUBLISHERNAME
--------------------------------------------------
Public Library
To Kill a Mockingbird
Harper Lee
J.B. Lippincott

10 rows selected.

SQL>
SQL> SELECT
2 b.author.name AS authorName,
3 b.title AS bookTitle
4 FROM
5 books b
6 ORDER BY
7 authorName;
AUTHORNAME
--------------------------------------------------
BOOKTITLE
--------------------------------------------------
F. Scott Fitzgerald
The Great Gatsby

George Orwell
1984

Harper Lee
To Kill a Mockingbird

AUTHORNAME
--------------------------------------------------
BOOKTITLE
--------------------------------------------------
J.D. Salinger
The Catcher in the Rye

J.K. Rowling
Harry Potter

J.R.R. Tolkien
The Hobbit

AUTHORNAME
--------------------------------------------------
BOOKTITLE
--------------------------------------------------
Jane Austen
Pride and Prejudice

Markus Zusak
The Book Thief

Paulo Coelho
The Alchemist

AUTHORNAME
--------------------------------------------------
BOOKTITLE
--------------------------------------------------
Yann Martel
Life of Pi

10 rows selected.

SQL>

You might also like