Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:01,370 --> 00:00:04,490
In this lesson, we're going
to look at external tables.
2
00:00:04,490 --> 00:00:08,540
And external tables are a pretty
interesting and useful feature
3
00:00:08,540 --> 00:00:12,160
of Oracle that have been
around for a few versions.
4
00:00:12,160 --> 00:00:16,340
And an external table is a way
to view a flat, delimited data
5
00:00:16,340 --> 00:00:19,070
file in a table format.
6
00:00:19,070 --> 00:00:21,860
So why would this
be useful to us?
7
00:00:21,860 --> 00:00:24,950
Well, instead of having
to directly load data
8
00:00:24,950 --> 00:00:27,860
into a table,
external tables let
9
00:00:27,860 --> 00:00:32,360
us create a table structure
with no storage in the database,
10
00:00:32,360 --> 00:00:35,300
but actually looks out
at the operating system,
11
00:00:35,300 --> 00:00:38,630
out in the file system,
and sees that data.
12
00:00:38,630 --> 00:00:41,810
So anytime you replace
or change the data
13
00:00:41,810 --> 00:00:44,600
that's in that base
data file, then
14
00:00:44,600 --> 00:00:46,400
Oracle can see
that as long as it
15
00:00:46,400 --> 00:00:50,070
conforms to the structure of
the table that you've created.
16
00:00:50,070 --> 00:00:52,610
And so this is going to require
a couple of different things,
17
00:00:52,610 --> 00:00:54,560
but it's actually
very easy to use
18
00:00:54,560 --> 00:00:57,050
and really quite a bit
simpler than using something
19
00:00:57,050 --> 00:01:00,590
like SQL Loader, which would
require a number of parameter
20
00:01:00,590 --> 00:01:02,390
and control files to be set up.
21
00:01:02,390 --> 00:01:06,140
So it requires the use of what
we call a directory object.
22
00:01:06,140 --> 00:01:08,420
This is just going
to be a database
23
00:01:08,420 --> 00:01:11,090
object that points to
a particular directory
24
00:01:11,090 --> 00:01:12,740
on the file system.
25
00:01:12,740 --> 00:01:16,730
And then we're also going to
need a specially created table.
26
00:01:16,730 --> 00:01:20,780
So first and foremost, let's
take a look at our directory
27
00:01:20,780 --> 00:01:21,930
that we have here.
28
00:01:21,930 --> 00:01:27,500
So in our base/loader directory,
we have a data file here,
29
00:01:27,500 --> 00:01:31,880
dept_load.dat, and it has
data that was exported out
30
00:01:31,880 --> 00:01:37,080
of the Dept table
that Scott uses.
31
00:01:37,080 --> 00:01:42,830
So I'm going to grab that path,
go into SQL Plus as Scott.
32
00:01:42,830 --> 00:01:45,750
I'm going to connect
as sysdba here
33
00:01:45,750 --> 00:01:48,400
to give Scott the
proper permissions,
34
00:01:48,400 --> 00:01:55,980
and create directory depth
external as, and then paste
35
00:01:55,980 --> 00:01:58,680
in that directory location.
36
00:01:58,680 --> 00:02:02,660
So now anytime that we
refer to a directory,
37
00:02:02,660 --> 00:02:06,300
the directory dept_external,
it's going to look
38
00:02:06,300 --> 00:02:09,720
in the e:/app/sries/loader
directory.
39
00:02:09,720 --> 00:02:13,020
So we're really just creating
a link in the database
40
00:02:13,020 --> 00:02:16,480
out to a folder on
the operating system.
41
00:02:16,480 --> 00:02:17,940
Now, Scott needs
to have permission
42
00:02:17,940 --> 00:02:20,000
to read and write
from this directory,
43
00:02:20,000 --> 00:02:25,590
so we're going to say
grant read on directory
44
00:02:25,590 --> 00:02:29,590
dept external to Scott.
45
00:02:29,590 --> 00:02:32,410
So we have our directory
object, and now we
46
00:02:32,410 --> 00:02:35,050
need our specially
created table.
47
00:02:35,050 --> 00:02:38,260
And so let's step through what's
special about this create table
48
00:02:38,260 --> 00:02:39,190
statement.
49
00:02:39,190 --> 00:02:41,890
So the first part,
here, we're calling
50
00:02:41,890 --> 00:02:44,690
the table dept external.
51
00:02:44,690 --> 00:02:47,830
And it's structured just as the
dept table in the Scott schema
52
00:02:47,830 --> 00:02:52,550
is-- same column names, data
types just for simplicity.
53
00:02:52,550 --> 00:02:54,700
So all of this is
just a basic table.
54
00:02:54,700 --> 00:02:56,740
Nothing special about that.
55
00:02:56,740 --> 00:03:00,830
It's the second section that
makes this an external table.
56
00:03:00,830 --> 00:03:03,830
So it says
organization external,
57
00:03:03,830 --> 00:03:08,500
and then in parentheses, we
use a number of different flags
58
00:03:08,500 --> 00:03:12,220
for the table to know exactly
where to look for its data--
59
00:03:12,220 --> 00:03:13,870
type, Oracle loader.
60
00:03:13,870 --> 00:03:16,420
So that means Oracle's
internal loading mechanism
61
00:03:16,420 --> 00:03:21,070
is going to be used to read data
from the file into the table.
62
00:03:21,070 --> 00:03:23,730
Default directory
is dept external,
63
00:03:23,730 --> 00:03:26,810
and that's the directory
object that we just created.
64
00:03:26,810 --> 00:03:28,600
And then we give it
some access parameters.
65
00:03:28,600 --> 00:03:31,450
It says fields
terminated by, comma.
66
00:03:31,450 --> 00:03:34,840
So it says when you read
the file, the delimiters
67
00:03:34,840 --> 00:03:37,030
in the file will be the commas.
68
00:03:37,030 --> 00:03:40,330
And then location
is dept_load.dat,
69
00:03:40,330 --> 00:03:44,290
and that is specified in
the dept external directory.
70
00:03:44,290 --> 00:03:47,440
So it looks at the directory
object, finds the path,
71
00:03:47,440 --> 00:03:53,930
and then uses this location
to find the actual data file.
72
00:03:53,930 --> 00:03:56,040
So we're going to create this.
73
00:03:56,040 --> 00:03:58,940
Now notice that we haven't done
any INSERT statements into dept
74
00:03:58,940 --> 00:04:00,890
external or anything like that.
75
00:04:00,890 --> 00:04:06,510
Let me just do select
star from dept external.
76
00:04:06,510 --> 00:04:08,970
And notice that it
reads the data directly
77
00:04:08,970 --> 00:04:11,080
from the file itself.
78
00:04:11,080 --> 00:04:16,870
What if we were to change
a value here, and save it,
79
00:04:16,870 --> 00:04:18,630
and rerun that SELECT statement?
80
00:04:18,630 --> 00:04:22,810
So right now, it's a deptno
of 40 as operations in Boston.
81
00:04:22,810 --> 00:04:25,490
And notice that it
reads the updated value.
82
00:04:25,490 --> 00:04:27,700
Anytime we do a
select, we're not
83
00:04:27,700 --> 00:04:30,070
selecting from a table that's
stored in the database.
84
00:04:30,070 --> 00:04:33,280
We're selecting from data
that's actually stored out
85
00:04:33,280 --> 00:04:34,690
on the operating system.
86
00:04:34,690 --> 00:04:36,520
So that's a little
bit of how useful
87
00:04:36,520 --> 00:04:38,930
an external table can be.
7194
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.