Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:01,380 --> 00:00:03,330
In this lesson, we're
going to take a look
2
00:00:03,330 --> 00:00:05,880
at objects in the database.
3
00:00:05,880 --> 00:00:09,540
Now, when we refer to an
object or a database object,
4
00:00:09,540 --> 00:00:14,760
we can be referring to tables,
indexes, procedures, packages,
5
00:00:14,760 --> 00:00:15,960
or the like.
6
00:00:15,960 --> 00:00:19,440
But starting in
version 8.0, Oracle
7
00:00:19,440 --> 00:00:23,130
was attempting to leverage
some of the recent excitement
8
00:00:23,130 --> 00:00:26,940
over object-oriented
technology and to apply this
9
00:00:26,940 --> 00:00:28,800
to database objects.
10
00:00:28,800 --> 00:00:31,560
The result is the
object technology
11
00:00:31,560 --> 00:00:33,390
that Oracle has in the database.
12
00:00:33,390 --> 00:00:37,860
Now, this is not something that
is very commonly used today.
13
00:00:37,860 --> 00:00:40,800
Some might even say it was
added more of a marketing idea
14
00:00:40,800 --> 00:00:42,060
more than anything.
15
00:00:42,060 --> 00:00:45,600
However, it is present in
the database, it can be used,
16
00:00:45,600 --> 00:00:48,840
and, indeed, companies do
use it because it really
17
00:00:48,840 --> 00:00:51,820
allows you to
multidimensionalize data,
18
00:00:51,820 --> 00:00:53,920
at least in a rudimentary way.
19
00:00:53,920 --> 00:00:57,240
Now, Oracle has other products
to do multidimensional data,
20
00:00:57,240 --> 00:01:01,260
but if you're going to use the
object-oriented methodology all
21
00:01:01,260 --> 00:01:03,180
of the way, so to
speak, then you
22
00:01:03,180 --> 00:01:07,200
can create objects and
object types and tables that
23
00:01:07,200 --> 00:01:10,600
use those object types
within the database.
24
00:01:10,600 --> 00:01:13,410
So the first thing we want
to do is create a type.
25
00:01:17,240 --> 00:01:20,930
So we're using a create
or replace type statement
26
00:01:20,930 --> 00:01:24,760
to create a type
called address_ot,
27
00:01:24,760 --> 00:01:27,530
and the ot as being object type.
28
00:01:27,530 --> 00:01:30,140
And then we use the
keywords AS OBJECT,
29
00:01:30,140 --> 00:01:32,870
and this refers to our
ability to instantiate it,
30
00:01:32,870 --> 00:01:35,210
in certain
circumstances, and use it
31
00:01:35,210 --> 00:01:37,490
in a more object-oriented way.
32
00:01:37,490 --> 00:01:42,260
Basically what this type is is
a complex or multidimensional
33
00:01:42,260 --> 00:01:43,380
data type.
34
00:01:43,380 --> 00:01:48,020
So we have data types, like
VARCHAR2, NUMBER, and DATE,
35
00:01:48,020 --> 00:01:50,420
those being scalar data types.
36
00:01:50,420 --> 00:01:54,230
These would be more of a
multi-scalar object type,
37
00:01:54,230 --> 00:01:55,580
or multidimensional.
38
00:01:55,580 --> 00:01:59,580
I think you'll see what
I mean as we create it.
39
00:01:59,580 --> 00:02:05,160
So we have a data type here that
we're creating, an object type.
40
00:02:05,160 --> 00:02:16,270
We have street address,
city, date code, and ZIP.
41
00:02:16,270 --> 00:02:18,280
And our type is created.
42
00:02:18,280 --> 00:02:20,440
So of course, when
we're creating a table,
43
00:02:20,440 --> 00:02:22,870
we could create
individual columns
44
00:02:22,870 --> 00:02:25,260
for street, city,
state, and ZIP.
45
00:02:25,260 --> 00:02:26,680
But what we're
doing here is we're
46
00:02:26,680 --> 00:02:31,550
encapsulating all of those into
a composite type, if you will,
47
00:02:31,550 --> 00:02:33,310
of address_ot.
48
00:02:33,310 --> 00:02:35,030
And we're creating
it as an object
49
00:02:35,030 --> 00:02:37,540
so it can be
instantiated in that way.
50
00:02:37,540 --> 00:02:40,750
So let's create a
table with this type.
51
00:02:40,750 --> 00:02:45,650
So this is a table emp_info
for just employee information.
52
00:02:53,280 --> 00:02:55,120
Now, notice what
we've done here.
53
00:02:55,120 --> 00:03:00,130
We've created a table with
four columns, a first name,
54
00:03:00,130 --> 00:03:01,330
last name, and birth date.
55
00:03:01,330 --> 00:03:05,260
And these are all what we would
consider normal or regular data
56
00:03:05,260 --> 00:03:06,190
types.
57
00:03:06,190 --> 00:03:08,710
But the address that we're
putting in our employee
58
00:03:08,710 --> 00:03:12,670
information is actually
an object type.
59
00:03:12,670 --> 00:03:19,290
So we're declaring this address
to be of the type address_ot.
60
00:03:19,290 --> 00:03:21,580
So how do we leverage this?
61
00:03:21,580 --> 00:03:27,850
So let's use a simple
anonymous block PL SQL.
62
00:03:27,850 --> 00:03:31,450
We'll declare a local
variable, lv_address.
63
00:03:38,260 --> 00:03:41,920
So for lv_address,
the local variable,
64
00:03:41,920 --> 00:03:46,280
we're assigning it to use
the address object type
65
00:03:46,280 --> 00:03:50,170
and to pass these
values into the object.
66
00:03:50,170 --> 00:03:53,530
And they correspond to
these four variables
67
00:03:53,530 --> 00:03:55,960
inside the object.
68
00:03:55,960 --> 00:04:03,080
I'm going to take this and
move the assignment down here.
69
00:04:03,080 --> 00:04:07,600
And here, we'll use
for instantiation.
70
00:04:07,600 --> 00:04:11,080
So we're declaring the
lv_address variable
71
00:04:11,080 --> 00:04:14,680
as being of data
type address_ot.
72
00:04:14,680 --> 00:04:17,770
Here, we assign a
value to the variable.
73
00:04:17,770 --> 00:04:21,160
And now we're going to
insert into the table.
74
00:04:21,160 --> 00:04:24,550
Now, notice, if we're going
to insert into this table,
75
00:04:24,550 --> 00:04:28,580
certainly we can insert a first
name, a last name, and a birth
76
00:04:28,580 --> 00:04:29,350
date.
77
00:04:29,350 --> 00:04:33,010
But how are we going to
insert an entire address
78
00:04:33,010 --> 00:04:35,830
into this object type?
79
00:04:35,830 --> 00:04:37,630
Well, we'll see the
methodology here.
80
00:04:43,450 --> 00:04:47,870
We simply say lv_address.
81
00:04:47,870 --> 00:04:52,200
Now, this references this
variable assignment here.
82
00:04:52,200 --> 00:04:58,810
And these values go back
to match our object type.
83
00:04:58,810 --> 00:05:01,080
Create that table.
84
00:05:01,080 --> 00:05:03,320
And run our statement.
85
00:05:03,320 --> 00:05:05,660
Anonymous block completed.
86
00:05:05,660 --> 00:05:14,580
And if we do a select count star
from emp info, highlight it,
87
00:05:14,580 --> 00:05:18,250
we notice that we have one row.
88
00:05:18,250 --> 00:05:24,110
So let's do select
star from emp info.
89
00:05:24,110 --> 00:05:26,960
Now, notice what we have here,
the first name, last name,
90
00:05:26,960 --> 00:05:29,030
and birthdate that we inserted.
91
00:05:29,030 --> 00:05:31,880
But for address, it
has to make a reference
92
00:05:31,880 --> 00:05:35,830
to the address_ot object type.
93
00:05:35,830 --> 00:05:38,860
And to pull this
out, we actually
94
00:05:38,860 --> 00:05:40,540
need to do a little extra work.
95
00:05:44,860 --> 00:05:50,440
We actually need to reference
the object type using an alias.
96
00:05:50,440 --> 00:05:53,650
So here, we have
the emp_info table
97
00:05:53,650 --> 00:05:57,150
that we reference
with the ei alias,
98
00:05:57,150 --> 00:05:59,890
and ei being the alias here.
99
00:05:59,890 --> 00:06:05,270
We say address, meaning
this column, and street.
100
00:06:05,270 --> 00:06:07,630
And this pulls out
the street that we
101
00:06:07,630 --> 00:06:10,880
inserted using the object type.
102
00:06:10,880 --> 00:06:14,050
So essentially, we've
instantiated this to pull back
103
00:06:14,050 --> 00:06:16,730
just the street information.
104
00:06:16,730 --> 00:06:19,940
And that goes back to
this part of the type.
105
00:06:19,940 --> 00:06:24,730
We could also
change this to city
106
00:06:24,730 --> 00:06:27,420
and pull back city
information, as well.
107
00:06:27,420 --> 00:06:30,890
So again, you may not
see this all that often,
108
00:06:30,890 --> 00:06:35,930
but this is kind of a basic look
at how object technology works
109
00:06:35,930 --> 00:06:38,190
within an Oracle database.
8699
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.