SlideShare a Scribd company logo
Considerations Before Creating a Database
• Database creation prepares several operating system files so they can
work together as an Oracle database.
• You need only create a database once, regardless of how many data files it
has or how many instances access it.
• Creating a database can also erase information in an existing database
and create a new database with the same name and physical structure.
Considerations Before Creating a Database
Creation Prerequisites
To create a new database, you must have the following:
• the operating system privileges associated with a fully operational database
administrator
• sufficient memory to start the Oracle instance
• sufficient disk storage space for the planned database on the computer that executes
Oracle
Object Types
• Listener port: Allows Oracle client connections to the database via the Oracle's
SQL*Net protocol. You can configure it during installation. Port 1521 is the default client
connections port, however, you can configure another TCP port via the Oracle
configuration and administration tools.
• A CDB includes zero, one, or many customer-created pluggable databases (PDBs). A
PDB is a portable collection of schemas, schema objects, and non-schema objects that
appears to an Oracle Net client as a non-CDB . ... A common user is a database user
known in every container .
• A pluggable database (PDB) is a portable collection of schemas, schema objects, and
nonschema objects that appears to an Oracle Net client as a non-CDB. PDBs can be
plugged into to CDBs. A CDB can contain multiple PDBs. Each PDB appears on the
network as a separate database.
Oracle create table statement
• To create table in oracle database, you use the create table statement.
• The basic syntax of the create table statement
CREATE TABLE schema_name.table_name(
Column_1 data_type column_constraint,
Column_2 data_type column_constraint,
……
Table_constraint
);
Oracle create table example
• The following example shows how to create a new table named persons in
csStudent schema
CREATE TABLE csStudent2.persons(
Person_id NUMBER GENERATED BY DEFAULT AS IDENTITY,
first_name VARCHAR2(50) NOT NULL,
last_name VARCHAR2(50) NOT NULL,
PRIMARY KEY(person_id)
);
create user csStudent2 IDENTIFIED by "oracle";
grant all privileges to csStudent identified by "oracle";
Oracle
Insert statement:
insert into CSSTUDENT.persons values(1, 'abebe', 'kebede’);
Select statement
select * from csstudent.persons;
Update statement
update csstudent.persons
set first_name = 'Belay'
where last_name = 'kebede’;
Drop table statement
drop table csStudent.persons;
Oracle alter table example
• The alter table statement is used to add, delete, or modify columns in existing table.
• the alter table statement is also used to add and drop various constraints on an existing table.
• Syntax:
ALTER TABLE table_name
ADD column_name datatype;
• Example:
Alter table csStudent.persons
Add email varchar(255);
Oracle alter table example
• Syntax:
ALTER TABLE table_name
DROP COLUMN column_name;
• Syntax:
ALTER TABLE table_name
MODIFY COLUMN column_name data_type;
Introduction to Oracle Objects
• Oracle object types are user-defined types that make it possible to model real-world
entities, such as customers and purchase orders, as objects in the database.
• New object types can be created from any built-in database types and any previously
created object types, object references, and collection types.
• Object types can work with complex data, such as images, audio, and video.
• Oracle Database stores metadata for user-defined types in a schema that is available to
SQL, PL/SQL, Java, and other languages.
• Object types are also known as user-defined types or ADTs.
Advantages of Objects
• In general, the object-type model is similar to the class mechanism found in C++ and Java.
• Like classes, the reusability of objects makes it possible to develop database applications
faster and more efficient.
• Objects offer other advantages over a purely relational approach, such as:
• Objects Can Encapsulate Operations Along with Data
• Objects Are Efficient
• Objects Can Represent Part-Whole Relationships
Database Features of Oracle Objects
• The following are features and concepts of the object-relational model that are
related to the database.
• Object types
• Object instances
• Object methods
• Object identifiers
• Object views
• Type inheritance
Object Types
• An object type is a kind of data type.
• You can use it in the same ways that you use standard data types such as NUMBER or
VARCHAR2.
Oracle Objects
• An object type allows you to create composite types.
• Using objects allow you to implement real world objects with specific structure of
data and methods for operating it.
• Objects have attributes and methods.
• Attributes are properties of an object and are used for storing an object's state; and
methods are used for modelling its behaviour.
• Objects are created using the CREATE [OR REPLACE] TYPE statement.
Oracle create object example
• an example to create a simple address object consisting of few attributes −
CREATE OR REPLACE TYPE address AS OBJECT
(house_no varchar2(10),
street varchar2(30),
city varchar2(20),
state varchar2(10),
pincode varchar2(10)
);
Oracle Methods
• Object methods implement behaviour that objects of that type perform.
• Object methods, also known as subprograms, are functions or procedures that you can
declare in an object type definition to implement behaviour that you want objects of that
type to perform.
• An application calls the subprograms to invoke the behaviour.
• Subprograms can be written in PL/SQL or virtually any other programming language.
• Member Methods
• Methods for Comparing Objects
• Static Methods
• Constructor Methods
• External Implemented Methods
Oracle Methods … Cont..
Member Methods
• Member methods provide an application with access to the data of an object instance.
• You define a member method in the object type for each operation that you want an
object of that type to be able to perform.
• Non-comparison member methods are declared as either MEMBER FUNCTION or
MEMBER PROCEDURE.
• Comparison methods use MAP MEMBER FUNCTION or ORDER MEMBER FUNCTION as
described in "Member Methods for Comparing Objects".
Oracle create object example
• Let's create one more object customer where we will wrap attributes and methods
together to have object-oriented feeling
CREATE OR REPLACE TYPE customer AS OBJECT
(code number(5),
name varchar2(30),
contact_no varchar2(12),
addr address,
member procedure display
);
Instantiating an Object
• Defining an object type provides a blueprint for the object.
• To use this object, you need to create instances of this object.
• You can access the attributes and methods of the object using the instance name and the
access operator (.) .
DECLARE
residence address;
BEGIN
residence := address('103A', 'M.G.Road', 'Jaipur', 'Rajasthan','201301');
dbms_output.put_line('House No: '|| residence.house_no);
dbms_output.put_line('Street: '|| residence.street);
dbms_output.put_line('City: '|| residence.city);
dbms_output.put_line('State: '|| residence.state);
dbms_output.put_line('Pincode: '|| residence.pincode);
END;
Member Methods
• Member methods are used for manipulating the attributes of the object.
• You provide the declaration of a member method while declaring the object type.
• The object body defines the code for the member methods. The object body is created
using the CREATE TYPE BODY statement.
• Constructors are functions that return a new object as its value.
• Every object has a system defined constructor method.
• The name of the constructor is same as the object type.
The comparison methods are used for comparing objects. There are two ways to compare
objects −
Map method
The Map method is a function implemented in such a way that its value depends upon the
value of the attributes.
Order method
The Order method implements some internal logic for comparing two objects.
https://docs.oracle.com/en/database/oracle/oracle-database/19/adobj/object-
methods.html#GUID-62ACE97A-5DD9-402A-B8B0-999AC488CAA2
Using Map method
CREATE OR REPLACE TYPE rectangle AS OBJECT
(
length number,
width number,
member function enlarge( inc number) return rectangle,
member procedure display,
map member function measure return number
);
The syntax to create a function in Oracle is:
CREATE [OR REPLACE] FUNCTION function_name
[ (parameter [,parameter]) ]
RETURN return_datatype
IS | AS
[declaration_section]
BEGIN
executable_section
[EXCEPTION
exception_section]
END [function_name];
Drop Function
Once you have created your function in Oracle, you might find that you need to remove
it from the database.
DROP FUNCTION function_name;
Creating the type
body
CREATE OR REPLACE TYPE BODY rectangle AS
MEMBER FUNCTION enlarge(inc number) return rectangle IS
BEGIN
return rectangle(self.length + inc, self.width + inc);
END enlarge;
MEMBER PROCEDURE display IS
BEGIN
dbms_output.put_line('Length: '|| length);
dbms_output.put_line('Width: '|| width);
END display;
MAP MEMBER FUNCTION measure return number IS
BEGIN
return (sqrt(length*length + width*width));
END measure;
END;
Now using the
rectangle object
and its member
functions
DECLARE
r1 rectangle;
r2 rectangle;
r3 rectangle;
inc_factor number := 5;
BEGIN
r1 := rectangle(3, 4);
r2 := rectangle(5, 7);
r3 := r1.enlarge(inc_factor);
r3.display;
IF (r1 > r2) THEN -- calling measure function
r1.display;
ELSE
r2.display;
END IF;
END;
Using Order method
CREATE OR REPLACE TYPE rectangle AS OBJECT
(length number,
width number,
member procedure display,
order member function measure(r rectangle) return number
);
Creating the type
body
CREATE OR REPLACE TYPE BODY rectangle AS
MEMBER PROCEDURE display IS
BEGIN
dbms_output.put_line('Length: '|| length);
dbms_output.put_line('Width: '|| width);
END display;
ORDER MEMBER FUNCTION measure(r rectangle) return number IS
BEGIN
IF(sqrt(self.length*self.length + self.width*self.width)>
sqrt(r.length*r.length + r.width*r.width)) then
return(1);
ELSE
return(-1);
END IF;
END measure;
END;
Now using the
rectangle object
and its member
functions
DECLARE
r1 rectangle;
r2 rectangle;
BEGIN
r1 := rectangle(23, 44);
r2 := rectangle(15, 17);
r1.display;
r2.display;
IF (r1 > r2) THEN -- calling measure function
r1.display;
ELSE
r2.display;
END IF;
END;
Here are some other differences between map and order methods
Automatic invocation
• Both map and order methods are called automatically when two objects of the same type need to
be compared.
Number of methods
• You can only have one map or order method in an object type definition.
Object type
• Only a type that is not derived from another type can declare an order method.
Return values
• Map methods return values that are Oracle built-in data types, or ANSI SQL types.
• Order methods return a negative number, zero, or a positive number.
You can implement either a map or order method in the CREATE TYPE and CREATE TYPE BODY
statements.
Inheritance for PL/SQL Objects
• PL/SQL allows creating object from the existing base objects.
• To implement inheritance, the base objects should be declared as NOT FINAL. The
default is FINAL.
• Let us create another object named TableTop, this is inherited from the Rectangle
object.
• For this, we need to create the base rectangle object −
create the base rectangle object
CREATE OR REPLACE TYPE rectangle AS OBJECT
(length number,
width number,
member function enlarge( inc number) return rectangle,
NOT FINAL member procedure display) NOT FINAL
Creating the base type body
CREATE OR REPLACE TYPE BODY rectangle AS
MEMBER FUNCTION enlarge(inc number) return rectangle IS
BEGIN
return rectangle(self.length + inc, self.width + inc);
END enlarge;
MEMBER PROCEDURE display IS
BEGIN
dbms_output.put_line('Length: '|| length);
dbms_output.put_line('Width: '|| width);
END display;
END;
Creating the child object tabletop
CREATE OR REPLACE TYPE tabletop UNDER rectangle
(
material varchar2(20),
OVERRIDING member procedure display
)
Creating the type body for the child object tabletop
CREATE OR REPLACE TYPE BODY tabletop AS
OVERRIDING MEMBER PROCEDURE display IS
BEGIN
dbms_output.put_line('Length: '|| length);
dbms_output.put_line('Width: '|| width);
dbms_output.put_line('Material: '|| material);
END display;
END;
Using the
tabletop object
and its member
functions
DECLARE
t1 tabletop;
t2 tabletop;
BEGIN
t1:= tabletop(20, 10, 'Wood');
t2 := tabletop(50, 30, 'Steel');
t1.display;
t2.display;
END;
Abstract Objects in PL/SQL
• The NOT INSTANTIABLE clause allows you to declare an abstract object. You cannot
use an abstract object as it is;
• you will have to create a subtype or child type of such objects to use its
functionalities.
create table csstudent.graphics_table (
bfile_id number,
bfile_desc varchar2(30),
bfile_loc bfile,
bfile_type varchar2(4)
);
INSERT INTO csstudent2.graphics_table
VALUES(4,'April Book of Days’, bfilename('C:UsersFauxDesktop','1.JPG'),'JPEG');
Ad

Recommended

Oodb
Oodb
danish wadood
 
Oodb
Oodb
danish wadood
 
Adv DB - Full Handout.pdf
Adv DB - Full Handout.pdf
3BRBoruMedia
 
OODB
OODB
rajukc47
 
Chapter 1 Concepts for Object-oriented Databases.pptx
Chapter 1 Concepts for Object-oriented Databases.pptx
haymanottaddess2015m
 
Object relational database management system
Object relational database management system
Saibee Alam
 
MIT302 Lesson 2_Advanced Database Systems.pptx
MIT302 Lesson 2_Advanced Database Systems.pptx
elsagalgao
 
oodb.ppt
oodb.ppt
ISHAAGARWAL75
 
Object relational and extended relational databases
Object relational and extended relational databases
Suhad Jihad
 
Chapt 1 odbms
Chapt 1 odbms
Sushil Kulkarni
 
ADBMS Object and Object Relational Databases
ADBMS Object and Object Relational Databases
Jayanthi Kannan MK
 
Database administration and management chapter 12
Database administration and management chapter 12
saniaafzalf1f2f3
 
Object oriented database concepts
Object oriented database concepts
Temesgenthanks
 
215 oodb
215 oodb
trhtom90
 
Object oriented database
Object oriented database
Md. Hasan Imam Bijoy
 
DDL. data defination language for creating database
DDL. data defination language for creating database
SHAKIR325211
 
Ch21-OODB.ppt
Ch21-OODB.ppt
fojep23014
 
Object-oriented Development with PL-SQL
Object-oriented Development with PL-SQL
Donald Bales
 
Object oriented development with PL/SQL
Object oriented development with PL/SQL
Donald Bales
 
oracle
oracle
KarthigaGunasekaran1
 
Odbms concepts
Odbms concepts
Dabbal Singh Mahara
 
Oracle Objects And Transactions
Oracle Objects And Transactions
tepsum
 
ordbms.ppt
ordbms.ppt
HODCA1
 
ORDBMS.pptx
ORDBMS.pptx
Anitta Antony
 
Lecture05sql 110406195130-phpapp02
Lecture05sql 110406195130-phpapp02
Lalit009kumar
 
Database Management System(UNIT 1)
Database Management System(UNIT 1)
Dr. SURBHI SAROHA
 
Database Management System(UNIT 1)
Database Management System(UNIT 1)
Dr. SURBHI SAROHA
 
Ordbms
Ordbms
ramandeep brar
 
Chapter 4 data structure and algorithm - Stacks and Queues
Chapter 4 data structure and algorithm - Stacks and Queues
afendimohammed288
 
Chapter 6 - Advanced Sorting Algorithms (1).ppt
Chapter 6 - Advanced Sorting Algorithms (1).ppt
afendimohammed288
 

More Related Content

Similar to Advanced database lab oracle structure query language (20)

Object relational and extended relational databases
Object relational and extended relational databases
Suhad Jihad
 
Chapt 1 odbms
Chapt 1 odbms
Sushil Kulkarni
 
ADBMS Object and Object Relational Databases
ADBMS Object and Object Relational Databases
Jayanthi Kannan MK
 
Database administration and management chapter 12
Database administration and management chapter 12
saniaafzalf1f2f3
 
Object oriented database concepts
Object oriented database concepts
Temesgenthanks
 
215 oodb
215 oodb
trhtom90
 
Object oriented database
Object oriented database
Md. Hasan Imam Bijoy
 
DDL. data defination language for creating database
DDL. data defination language for creating database
SHAKIR325211
 
Ch21-OODB.ppt
Ch21-OODB.ppt
fojep23014
 
Object-oriented Development with PL-SQL
Object-oriented Development with PL-SQL
Donald Bales
 
Object oriented development with PL/SQL
Object oriented development with PL/SQL
Donald Bales
 
oracle
oracle
KarthigaGunasekaran1
 
Odbms concepts
Odbms concepts
Dabbal Singh Mahara
 
Oracle Objects And Transactions
Oracle Objects And Transactions
tepsum
 
ordbms.ppt
ordbms.ppt
HODCA1
 
ORDBMS.pptx
ORDBMS.pptx
Anitta Antony
 
Lecture05sql 110406195130-phpapp02
Lecture05sql 110406195130-phpapp02
Lalit009kumar
 
Database Management System(UNIT 1)
Database Management System(UNIT 1)
Dr. SURBHI SAROHA
 
Database Management System(UNIT 1)
Database Management System(UNIT 1)
Dr. SURBHI SAROHA
 
Ordbms
Ordbms
ramandeep brar
 
Object relational and extended relational databases
Object relational and extended relational databases
Suhad Jihad
 
ADBMS Object and Object Relational Databases
ADBMS Object and Object Relational Databases
Jayanthi Kannan MK
 
Database administration and management chapter 12
Database administration and management chapter 12
saniaafzalf1f2f3
 
Object oriented database concepts
Object oriented database concepts
Temesgenthanks
 
DDL. data defination language for creating database
DDL. data defination language for creating database
SHAKIR325211
 
Object-oriented Development with PL-SQL
Object-oriented Development with PL-SQL
Donald Bales
 
Object oriented development with PL/SQL
Object oriented development with PL/SQL
Donald Bales
 
Oracle Objects And Transactions
Oracle Objects And Transactions
tepsum
 
ordbms.ppt
ordbms.ppt
HODCA1
 
Lecture05sql 110406195130-phpapp02
Lecture05sql 110406195130-phpapp02
Lalit009kumar
 
Database Management System(UNIT 1)
Database Management System(UNIT 1)
Dr. SURBHI SAROHA
 
Database Management System(UNIT 1)
Database Management System(UNIT 1)
Dr. SURBHI SAROHA
 

More from afendimohammed288 (8)

Chapter 4 data structure and algorithm - Stacks and Queues
Chapter 4 data structure and algorithm - Stacks and Queues
afendimohammed288
 
Chapter 6 - Advanced Sorting Algorithms (1).ppt
Chapter 6 - Advanced Sorting Algorithms (1).ppt
afendimohammed288
 
Chapter 4 Discrete Mathematics and Combinatorics.pdf
Chapter 4 Discrete Mathematics and Combinatorics.pdf
afendimohammed288
 
Chapter (Two) The best lecture PowerPoint
Chapter (Two) The best lecture PowerPoint
afendimohammed288
 
Computer organization and architecture chapter 5
Computer organization and architecture chapter 5
afendimohammed288
 
Advanced database chapter three PowerPoint
Advanced database chapter three PowerPoint
afendimohammed288
 
Computer organizatin.Chapter Seven.pptxs
Computer organizatin.Chapter Seven.pptxs
afendimohammed288
 
General Biology.-Chapter one.PowerPoints
General Biology.-Chapter one.PowerPoints
afendimohammed288
 
Chapter 4 data structure and algorithm - Stacks and Queues
Chapter 4 data structure and algorithm - Stacks and Queues
afendimohammed288
 
Chapter 6 - Advanced Sorting Algorithms (1).ppt
Chapter 6 - Advanced Sorting Algorithms (1).ppt
afendimohammed288
 
Chapter 4 Discrete Mathematics and Combinatorics.pdf
Chapter 4 Discrete Mathematics and Combinatorics.pdf
afendimohammed288
 
Chapter (Two) The best lecture PowerPoint
Chapter (Two) The best lecture PowerPoint
afendimohammed288
 
Computer organization and architecture chapter 5
Computer organization and architecture chapter 5
afendimohammed288
 
Advanced database chapter three PowerPoint
Advanced database chapter three PowerPoint
afendimohammed288
 
Computer organizatin.Chapter Seven.pptxs
Computer organizatin.Chapter Seven.pptxs
afendimohammed288
 
General Biology.-Chapter one.PowerPoints
General Biology.-Chapter one.PowerPoints
afendimohammed288
 
Ad

Recently uploaded (20)

Overview of Off Boarding in Odoo 18 Employees
Overview of Off Boarding in Odoo 18 Employees
Celine George
 
Chalukyas of Gujrat, Solanki Dynasty NEP.pptx
Chalukyas of Gujrat, Solanki Dynasty NEP.pptx
Dr. Ravi Shankar Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
razelitouali
 
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
aditya23173
 
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Shrutidhara2
 
ROLE PLAY: FIRST AID -CPR & RECOVERY POSITION.pptx
ROLE PLAY: FIRST AID -CPR & RECOVERY POSITION.pptx
Belicia R.S
 
Paper 108 | Thoreau’s Influence on Gandhi: The Evolution of Civil Disobedience
Paper 108 | Thoreau’s Influence on Gandhi: The Evolution of Civil Disobedience
Rajdeep Bavaliya
 
Sustainable Innovation with Immersive Learning
Sustainable Innovation with Immersive Learning
Leonel Morgado
 
How to Create an Event in Odoo 18 - Odoo 18 Slides
How to Create an Event in Odoo 18 - Odoo 18 Slides
Celine George
 
Battle of Bookworms 2025 - U25 Literature Quiz by Pragya
Battle of Bookworms 2025 - U25 Literature Quiz by Pragya
Pragya - UEM Kolkata Quiz Club
 
BUSINESS QUIZ PRELIMS | QUIZ CLUB OF PSGCAS | 9 SEPTEMBER 2024
BUSINESS QUIZ PRELIMS | QUIZ CLUB OF PSGCAS | 9 SEPTEMBER 2024
Quiz Club of PSG College of Arts & Science
 
Nice Dream.pdf /
Nice Dream.pdf /
ErinUsher3
 
Allomorps and word formation.pptx - Google Slides.pdf
Allomorps and word formation.pptx - Google Slides.pdf
Abha Pandey
 
Unit 3 Poster Sketches with annotations.pptx
Unit 3 Poster Sketches with annotations.pptx
bobby205207
 
Rai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptx
Rai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptx
Dr. Ravi Shankar Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
ABCs of Bookkeeping for Nonprofits TechSoup.pdf
ABCs of Bookkeeping for Nonprofits TechSoup.pdf
TechSoup
 
How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18
Celine George
 
PEST OF WHEAT SORGHUM BAJRA and MINOR MILLETS.pptx
PEST OF WHEAT SORGHUM BAJRA and MINOR MILLETS.pptx
Arshad Shaikh
 
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Restu Bias Primandhika
 
How to Manage Multi Language for Invoice in Odoo 18
How to Manage Multi Language for Invoice in Odoo 18
Celine George
 
Overview of Off Boarding in Odoo 18 Employees
Overview of Off Boarding in Odoo 18 Employees
Celine George
 
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
razelitouali
 
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
aditya23173
 
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Shrutidhara2
 
ROLE PLAY: FIRST AID -CPR & RECOVERY POSITION.pptx
ROLE PLAY: FIRST AID -CPR & RECOVERY POSITION.pptx
Belicia R.S
 
Paper 108 | Thoreau’s Influence on Gandhi: The Evolution of Civil Disobedience
Paper 108 | Thoreau’s Influence on Gandhi: The Evolution of Civil Disobedience
Rajdeep Bavaliya
 
Sustainable Innovation with Immersive Learning
Sustainable Innovation with Immersive Learning
Leonel Morgado
 
How to Create an Event in Odoo 18 - Odoo 18 Slides
How to Create an Event in Odoo 18 - Odoo 18 Slides
Celine George
 
Battle of Bookworms 2025 - U25 Literature Quiz by Pragya
Battle of Bookworms 2025 - U25 Literature Quiz by Pragya
Pragya - UEM Kolkata Quiz Club
 
Nice Dream.pdf /
Nice Dream.pdf /
ErinUsher3
 
Allomorps and word formation.pptx - Google Slides.pdf
Allomorps and word formation.pptx - Google Slides.pdf
Abha Pandey
 
Unit 3 Poster Sketches with annotations.pptx
Unit 3 Poster Sketches with annotations.pptx
bobby205207
 
ABCs of Bookkeeping for Nonprofits TechSoup.pdf
ABCs of Bookkeeping for Nonprofits TechSoup.pdf
TechSoup
 
How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18
Celine George
 
PEST OF WHEAT SORGHUM BAJRA and MINOR MILLETS.pptx
PEST OF WHEAT SORGHUM BAJRA and MINOR MILLETS.pptx
Arshad Shaikh
 
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Restu Bias Primandhika
 
How to Manage Multi Language for Invoice in Odoo 18
How to Manage Multi Language for Invoice in Odoo 18
Celine George
 
Ad

Advanced database lab oracle structure query language

  • 1. Considerations Before Creating a Database • Database creation prepares several operating system files so they can work together as an Oracle database. • You need only create a database once, regardless of how many data files it has or how many instances access it. • Creating a database can also erase information in an existing database and create a new database with the same name and physical structure.
  • 2. Considerations Before Creating a Database Creation Prerequisites To create a new database, you must have the following: • the operating system privileges associated with a fully operational database administrator • sufficient memory to start the Oracle instance • sufficient disk storage space for the planned database on the computer that executes Oracle
  • 3. Object Types • Listener port: Allows Oracle client connections to the database via the Oracle's SQL*Net protocol. You can configure it during installation. Port 1521 is the default client connections port, however, you can configure another TCP port via the Oracle configuration and administration tools. • A CDB includes zero, one, or many customer-created pluggable databases (PDBs). A PDB is a portable collection of schemas, schema objects, and non-schema objects that appears to an Oracle Net client as a non-CDB . ... A common user is a database user known in every container . • A pluggable database (PDB) is a portable collection of schemas, schema objects, and nonschema objects that appears to an Oracle Net client as a non-CDB. PDBs can be plugged into to CDBs. A CDB can contain multiple PDBs. Each PDB appears on the network as a separate database.
  • 4. Oracle create table statement • To create table in oracle database, you use the create table statement. • The basic syntax of the create table statement CREATE TABLE schema_name.table_name( Column_1 data_type column_constraint, Column_2 data_type column_constraint, …… Table_constraint );
  • 5. Oracle create table example • The following example shows how to create a new table named persons in csStudent schema CREATE TABLE csStudent2.persons( Person_id NUMBER GENERATED BY DEFAULT AS IDENTITY, first_name VARCHAR2(50) NOT NULL, last_name VARCHAR2(50) NOT NULL, PRIMARY KEY(person_id) );
  • 6. create user csStudent2 IDENTIFIED by "oracle"; grant all privileges to csStudent identified by "oracle";
  • 7. Oracle Insert statement: insert into CSSTUDENT.persons values(1, 'abebe', 'kebede’); Select statement select * from csstudent.persons; Update statement update csstudent.persons set first_name = 'Belay' where last_name = 'kebede’; Drop table statement drop table csStudent.persons;
  • 8. Oracle alter table example • The alter table statement is used to add, delete, or modify columns in existing table. • the alter table statement is also used to add and drop various constraints on an existing table. • Syntax: ALTER TABLE table_name ADD column_name datatype; • Example: Alter table csStudent.persons Add email varchar(255);
  • 9. Oracle alter table example • Syntax: ALTER TABLE table_name DROP COLUMN column_name; • Syntax: ALTER TABLE table_name MODIFY COLUMN column_name data_type;
  • 10. Introduction to Oracle Objects • Oracle object types are user-defined types that make it possible to model real-world entities, such as customers and purchase orders, as objects in the database. • New object types can be created from any built-in database types and any previously created object types, object references, and collection types. • Object types can work with complex data, such as images, audio, and video. • Oracle Database stores metadata for user-defined types in a schema that is available to SQL, PL/SQL, Java, and other languages. • Object types are also known as user-defined types or ADTs.
  • 11. Advantages of Objects • In general, the object-type model is similar to the class mechanism found in C++ and Java. • Like classes, the reusability of objects makes it possible to develop database applications faster and more efficient. • Objects offer other advantages over a purely relational approach, such as: • Objects Can Encapsulate Operations Along with Data • Objects Are Efficient • Objects Can Represent Part-Whole Relationships
  • 12. Database Features of Oracle Objects • The following are features and concepts of the object-relational model that are related to the database. • Object types • Object instances • Object methods • Object identifiers • Object views • Type inheritance
  • 13. Object Types • An object type is a kind of data type. • You can use it in the same ways that you use standard data types such as NUMBER or VARCHAR2.
  • 14. Oracle Objects • An object type allows you to create composite types. • Using objects allow you to implement real world objects with specific structure of data and methods for operating it. • Objects have attributes and methods. • Attributes are properties of an object and are used for storing an object's state; and methods are used for modelling its behaviour. • Objects are created using the CREATE [OR REPLACE] TYPE statement.
  • 15. Oracle create object example • an example to create a simple address object consisting of few attributes − CREATE OR REPLACE TYPE address AS OBJECT (house_no varchar2(10), street varchar2(30), city varchar2(20), state varchar2(10), pincode varchar2(10) );
  • 16. Oracle Methods • Object methods implement behaviour that objects of that type perform. • Object methods, also known as subprograms, are functions or procedures that you can declare in an object type definition to implement behaviour that you want objects of that type to perform. • An application calls the subprograms to invoke the behaviour. • Subprograms can be written in PL/SQL or virtually any other programming language.
  • 17. • Member Methods • Methods for Comparing Objects • Static Methods • Constructor Methods • External Implemented Methods Oracle Methods … Cont..
  • 18. Member Methods • Member methods provide an application with access to the data of an object instance. • You define a member method in the object type for each operation that you want an object of that type to be able to perform. • Non-comparison member methods are declared as either MEMBER FUNCTION or MEMBER PROCEDURE. • Comparison methods use MAP MEMBER FUNCTION or ORDER MEMBER FUNCTION as described in "Member Methods for Comparing Objects".
  • 19. Oracle create object example • Let's create one more object customer where we will wrap attributes and methods together to have object-oriented feeling CREATE OR REPLACE TYPE customer AS OBJECT (code number(5), name varchar2(30), contact_no varchar2(12), addr address, member procedure display );
  • 20. Instantiating an Object • Defining an object type provides a blueprint for the object. • To use this object, you need to create instances of this object. • You can access the attributes and methods of the object using the instance name and the access operator (.) .
  • 21. DECLARE residence address; BEGIN residence := address('103A', 'M.G.Road', 'Jaipur', 'Rajasthan','201301'); dbms_output.put_line('House No: '|| residence.house_no); dbms_output.put_line('Street: '|| residence.street); dbms_output.put_line('City: '|| residence.city); dbms_output.put_line('State: '|| residence.state); dbms_output.put_line('Pincode: '|| residence.pincode); END;
  • 22. Member Methods • Member methods are used for manipulating the attributes of the object. • You provide the declaration of a member method while declaring the object type. • The object body defines the code for the member methods. The object body is created using the CREATE TYPE BODY statement. • Constructors are functions that return a new object as its value. • Every object has a system defined constructor method. • The name of the constructor is same as the object type.
  • 23. The comparison methods are used for comparing objects. There are two ways to compare objects − Map method The Map method is a function implemented in such a way that its value depends upon the value of the attributes. Order method The Order method implements some internal logic for comparing two objects. https://docs.oracle.com/en/database/oracle/oracle-database/19/adobj/object- methods.html#GUID-62ACE97A-5DD9-402A-B8B0-999AC488CAA2
  • 24. Using Map method CREATE OR REPLACE TYPE rectangle AS OBJECT ( length number, width number, member function enlarge( inc number) return rectangle, member procedure display, map member function measure return number );
  • 25. The syntax to create a function in Oracle is: CREATE [OR REPLACE] FUNCTION function_name [ (parameter [,parameter]) ] RETURN return_datatype IS | AS [declaration_section] BEGIN executable_section [EXCEPTION exception_section] END [function_name]; Drop Function Once you have created your function in Oracle, you might find that you need to remove it from the database. DROP FUNCTION function_name;
  • 26. Creating the type body CREATE OR REPLACE TYPE BODY rectangle AS MEMBER FUNCTION enlarge(inc number) return rectangle IS BEGIN return rectangle(self.length + inc, self.width + inc); END enlarge; MEMBER PROCEDURE display IS BEGIN dbms_output.put_line('Length: '|| length); dbms_output.put_line('Width: '|| width); END display; MAP MEMBER FUNCTION measure return number IS BEGIN return (sqrt(length*length + width*width)); END measure; END;
  • 27. Now using the rectangle object and its member functions DECLARE r1 rectangle; r2 rectangle; r3 rectangle; inc_factor number := 5; BEGIN r1 := rectangle(3, 4); r2 := rectangle(5, 7); r3 := r1.enlarge(inc_factor); r3.display; IF (r1 > r2) THEN -- calling measure function r1.display; ELSE r2.display; END IF; END;
  • 28. Using Order method CREATE OR REPLACE TYPE rectangle AS OBJECT (length number, width number, member procedure display, order member function measure(r rectangle) return number );
  • 29. Creating the type body CREATE OR REPLACE TYPE BODY rectangle AS MEMBER PROCEDURE display IS BEGIN dbms_output.put_line('Length: '|| length); dbms_output.put_line('Width: '|| width); END display; ORDER MEMBER FUNCTION measure(r rectangle) return number IS BEGIN IF(sqrt(self.length*self.length + self.width*self.width)> sqrt(r.length*r.length + r.width*r.width)) then return(1); ELSE return(-1); END IF; END measure; END;
  • 30. Now using the rectangle object and its member functions DECLARE r1 rectangle; r2 rectangle; BEGIN r1 := rectangle(23, 44); r2 := rectangle(15, 17); r1.display; r2.display; IF (r1 > r2) THEN -- calling measure function r1.display; ELSE r2.display; END IF; END;
  • 31. Here are some other differences between map and order methods Automatic invocation • Both map and order methods are called automatically when two objects of the same type need to be compared. Number of methods • You can only have one map or order method in an object type definition. Object type • Only a type that is not derived from another type can declare an order method. Return values • Map methods return values that are Oracle built-in data types, or ANSI SQL types. • Order methods return a negative number, zero, or a positive number. You can implement either a map or order method in the CREATE TYPE and CREATE TYPE BODY statements.
  • 32. Inheritance for PL/SQL Objects • PL/SQL allows creating object from the existing base objects. • To implement inheritance, the base objects should be declared as NOT FINAL. The default is FINAL. • Let us create another object named TableTop, this is inherited from the Rectangle object. • For this, we need to create the base rectangle object −
  • 33. create the base rectangle object CREATE OR REPLACE TYPE rectangle AS OBJECT (length number, width number, member function enlarge( inc number) return rectangle, NOT FINAL member procedure display) NOT FINAL
  • 34. Creating the base type body CREATE OR REPLACE TYPE BODY rectangle AS MEMBER FUNCTION enlarge(inc number) return rectangle IS BEGIN return rectangle(self.length + inc, self.width + inc); END enlarge; MEMBER PROCEDURE display IS BEGIN dbms_output.put_line('Length: '|| length); dbms_output.put_line('Width: '|| width); END display; END;
  • 35. Creating the child object tabletop CREATE OR REPLACE TYPE tabletop UNDER rectangle ( material varchar2(20), OVERRIDING member procedure display )
  • 36. Creating the type body for the child object tabletop CREATE OR REPLACE TYPE BODY tabletop AS OVERRIDING MEMBER PROCEDURE display IS BEGIN dbms_output.put_line('Length: '|| length); dbms_output.put_line('Width: '|| width); dbms_output.put_line('Material: '|| material); END display; END;
  • 37. Using the tabletop object and its member functions DECLARE t1 tabletop; t2 tabletop; BEGIN t1:= tabletop(20, 10, 'Wood'); t2 := tabletop(50, 30, 'Steel'); t1.display; t2.display; END;
  • 38. Abstract Objects in PL/SQL • The NOT INSTANTIABLE clause allows you to declare an abstract object. You cannot use an abstract object as it is; • you will have to create a subtype or child type of such objects to use its functionalities.
  • 39. create table csstudent.graphics_table ( bfile_id number, bfile_desc varchar2(30), bfile_loc bfile, bfile_type varchar2(4) ); INSERT INTO csstudent2.graphics_table VALUES(4,'April Book of Days’, bfilename('C:UsersFauxDesktop','1.JPG'),'JPEG');