What is structured and unstructured data?
Structured data is the data which is organized in such a way that relational database can easily search. Unstructured data is not properly organized and this increases the compilation time of a program.
Literal Data Type
The literal value may be a simple structure or complex structure.
Types of literals can be:
1. Atomic literal- Atomic literals also called as primary expression.
- They can take the values Long, Short, Character, Enumeration, Boolean.
2. Collection literals- Collection literals specify the values which are a collection of objects.
For example: array, list etc.
3. Structure literals- A structure literal belongs to values which are constructed by using type constructor Structure literal.
- Structure literals for object models are Date, Interval, Time, Timestamp.
Operations on structured and unstructured data
Some functions, which are very important to create and manipulate an object are:1. Type constructor
- Type constructor is used to create UDT (user defined data types),which is needed if data-type is complex.
- A row type is a sequence of field name or data type.
Syntax
CREATE TYPE Row_Type_Name AS [ROW]
(<component declarations>)
Where the keyword ROW is optional
Example : Type constructor is used to create table of student information
Student_name
CREATE TYPE Name_types As (
FName VARCHAR (20),
MName VARCHAR (20),
LName VARCHAR (20), );
Student
CREATE TYPE Student_type AS (
SName Name_type,
Phone VARCHAR (10),
DOB DATE);
Creating DEPT
CREAT TABLE DEPT AS (
DName VARCHAR (15),
LOC ROW (City VARCHAR (15),
State VARCHAR(15),
Country VARCHAR (20)));
Now, to insert the data in DEPT table
INSERT INTO DEPT
VALUES ( 'COMP', ROW ('Pune', 'Maharastra', 'India'));
2. Object identifier by using References
A row type can be used as type (Data type) for attribute. It can be used to create tables.
Some functions to create an object identifier are as given below:
1) Create a system generated object identifier
Syntax
REF IS <oid_attribute> <value_generation_method>;
This is a alternative method to provide primary key value and system can generate unique identifier.
Example : Create a system generated object identifier using primary key
CREATE TABLE Dept OF dept_type (
REF IS Dept_id SYSTEM GENERATED,
PRIMARY KEY (Deptname));
2) Reference attribute
Component tuple of one relation can be referenced to tuple of another table.
Example : Create a table using SCOPE keyword
CREATE TYPE section_type AS (
Department REF (Dept_type) SCOPE (Dept)
);
CREATE TABLE section_type;
In the above example, keyword SCOPE specifies the name of the table whose tuple can be referenced by the reference attribute.
3) Dot notation
A dot (.) notation is used for building path which refers to the component attribute of various row types.
Example : Create a table using dot notation
SELECT b.Branch_id
FROM Branch AS b
WHERE b.College_name= 'PVG'
3. Data encapsulation and ADT
User can create own user-defined type with its behavioral and specification by specifying operations to attributes.
Syntax
CREATE TYPE <type-name>
(
Component attributes and their types
EQUAL and LESS THAN functions
);
Example : Create a user defined type for Student_contact as
CREATE TYPE Student_contact AS (
Street VARCHAR (20),
City VARCHAR (15),
Phone Numeric (10),
Function Age (s DOB) RETURNS INTEGER
RETURN /* this is the function to calculate age from DOB
END
);