Unit 5 - Object Relational and No-SQL Databases v1 1
Unit 5 - Object Relational and No-SQL Databases v1 1
street VARCHAR2(20),
city VARCHAR2(10),
state CHAR(2),
zip VARCHAR2(10));
Example for an UDT
CREATE TYPE dept_t AS OBJECT (
deptno NUMBER,
deptname VARCHAR2(20),
address address_t );
Object Table
● A table based on a single object serves as a data
type of each of the rows within that table.
● Such a table is referred to as an object table, and it
contains row objects. In other words, each row is an
object instance.
● Row object tables can be queried by using standard
SQL.
Creating a Table using UDT
CREATE TABLE table obj_dept OF dept_t (
DESC obj_dept;
Object Table
● INSERT INTO obj_dept VALUES(500, 'Admin',
address_t('ABC st','Chennai','TN','600063'));
● INSERT INTO obj_dept VALUES(501, 'HR',
address_t('XYZ st','Mumbai','MH','405006'));
Encapsulation
Observer and Mutator Functions
● You can encapsulate each attribute of structured types by
providing a pair of functions to access the attribute.
● an observer (get) function and a mutator (set) function.
RETURN p.fName;
Encapsulation: Observer and Mutator Functions
FUNCTION fName(p PersonType RESULT, newValue VARCHAR(15))
RETURNS PersonType
BEGIN
p.fName = newValue;
RETURN p;
END;
Member Functions in an Object
CREATE OR REPLACE TYPE person_typ AS OBJECT (
idno NUMBER,
name VARCHAR2(30),
phone VARCHAR2(20),
● The constructor function has the same name and type as the UDT, takes
zero arguments, and returns a new instance of the type with the attributes
set to their default value.
● Each method must have the same name as the structured type but the
parameters must be different from the system-supplied constructor.
BEGIN
RETURN SELF;
END;
Constructor Functions
SET p = NEW PersonType();
empNo VARCHAR2(4),
address AddressType,
branchNo VARCHAR2(4),
address AddressType,
nested tables
Array Types
● An array is an ordered set of data elements that are all of the
same data type.
fName VARCHAR2(15),
lName VARCHAR2(15),
telNo VARCHAR2(13));
• No two functions in the same schema are allowed to have the same
signature, that is, the same number of arguments, the same data types
for each argument, and the same return type.
• No two procedures in the same schema are allowed to have the same
name and the same number of parameters.
Instance method invocation
● The mechanism for determining the appropriate
invocation of an instance method is divided into two
phases representing static analysis and runtime
execution.
Method Invocation – Static Analysis
• All routines with the appropriate name are identified (all remaining routines are
eliminated).
• All procedures/functions and all methods for which the user does not have
EXECUTE privilege are eliminated.
• All methods that are not associated with the declared type (or subtype) of the
implicit SELF argument are eliminated.
• All methods whose parameters are not equal to the number of arguments in the
method invocation are eliminated.
• For the methods that remain, the system checks that the data type of each
parameter matches the precedence list of the corresponding argument,
eliminating those methods that do not match.
• If there are no candidate methods remaining a syntax error occurs.
Runtime Phase
● If the most specific type of the runtime value of the implicit
argument to the method invocation has a type definition that
includes one of the candidate methods
then that method is selected for execution.
• Some say the term “NoSQL” stands for “non SQL” while
others say it stands for “not only SQL.”
• scan ‘EMPLOYEE’