Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:01,420 --> 00:00:03,580
In this lesson, we're
going to look at data
2
00:00:03,580 --> 00:00:06,280
migration using SQL Loader.
3
00:00:06,280 --> 00:00:08,800
So data migration is
the act of moving data
4
00:00:08,800 --> 00:00:13,450
from one place to another and
often from an external source
5
00:00:13,450 --> 00:00:15,580
into an Oracle database.
6
00:00:15,580 --> 00:00:19,250
So there are numerous ways
to load data into a database.
7
00:00:19,250 --> 00:00:21,740
So we're going to take
a look at SQL Loader.
8
00:00:21,740 --> 00:00:25,330
So SQL Loader is somewhat
of an older tool,
9
00:00:25,330 --> 00:00:27,550
but it's still very
commonly used today
10
00:00:27,550 --> 00:00:31,480
because it's really, really
good at taking file data, just
11
00:00:31,480 --> 00:00:35,470
straight delimited data,
let's say, or even raw data,
12
00:00:35,470 --> 00:00:37,630
and loading it into tables.
13
00:00:37,630 --> 00:00:39,730
There's quite a bit of
work in setting it up.
14
00:00:39,730 --> 00:00:41,980
But once you do that
work, it's something
15
00:00:41,980 --> 00:00:44,920
that doesn't have to be repeated
unless your table changes,
16
00:00:44,920 --> 00:00:46,970
and it can be very, very fast.
17
00:00:46,970 --> 00:00:52,070
So SQL Loader is going to read
data from a delimited file
18
00:00:52,070 --> 00:00:54,290
and load it into a table.
19
00:00:54,290 --> 00:00:57,700
So a delimited file would be
just a file where the data is
20
00:00:57,700 --> 00:01:02,050
delimited by some delimiter,
like a comma-delimited file,
21
00:01:02,050 --> 00:01:05,200
or pipe delimited, or
any number of characters,
22
00:01:05,200 --> 00:01:08,380
and you just need to specify
what the delimiter is.
23
00:01:08,380 --> 00:01:11,560
It can also read
data from flat files
24
00:01:11,560 --> 00:01:15,620
and load it into tables
based on character positions.
25
00:01:15,620 --> 00:01:19,150
So it can say, take the first
five characters of the file
26
00:01:19,150 --> 00:01:21,730
and load that into the first
column, and then the next 10,
27
00:01:21,730 --> 00:01:25,570
and load that into the second
column, so on and so forth.
28
00:01:25,570 --> 00:01:28,270
And often this is used
with mainframe data,
29
00:01:28,270 --> 00:01:32,080
in conjunction with mainframe
data, where the Oracle
30
00:01:32,080 --> 00:01:35,680
database is in the mid tier,
kind of, of the enterprise
31
00:01:35,680 --> 00:01:40,680
and receives data that's
stored in a mainframe system.
32
00:01:40,680 --> 00:01:44,390
So SQL Loader can run using
two different methods.
33
00:01:44,390 --> 00:01:46,480
The first is the
conventional path,
34
00:01:46,480 --> 00:01:48,430
and all that the
conventional path does
35
00:01:48,430 --> 00:01:51,640
is simply construct
INSERT statements using
36
00:01:51,640 --> 00:01:54,880
the delimited or raw
data and then just run
37
00:01:54,880 --> 00:01:56,530
those INSERT statements.
38
00:01:56,530 --> 00:01:59,050
So conventional
path is the safest,
39
00:01:59,050 --> 00:02:01,840
if you would, but
only in terms of being
40
00:02:01,840 --> 00:02:05,050
able to use all kinds
of different data types.
41
00:02:05,050 --> 00:02:08,860
There's nothing inherently
unsafe about either way,
42
00:02:08,860 --> 00:02:13,060
or either method, except that
the second method, direct path,
43
00:02:13,060 --> 00:02:16,990
can't necessarily use some of
the more esoteric data types
44
00:02:16,990 --> 00:02:19,900
that people sometimes
have in a database.
45
00:02:19,900 --> 00:02:23,170
Direct path, however,
constructs blocks
46
00:02:23,170 --> 00:02:26,920
from that data that are written
directly into the database.
47
00:02:26,920 --> 00:02:30,790
And it actually bypasses
the database buffer cache
48
00:02:30,790 --> 00:02:32,860
and the caching
that needs to occur.
49
00:02:32,860 --> 00:02:37,370
And for that reason,
direct path is much faster.
50
00:02:37,370 --> 00:02:40,750
So it doesn't have to construct
and run INSERT statements.
51
00:02:40,750 --> 00:02:43,630
It just constructs the blocks
that are directly written.
52
00:02:43,630 --> 00:02:45,820
And so whenever
possible, we definitely
53
00:02:45,820 --> 00:02:47,350
want to use the direct path.
54
00:02:47,350 --> 00:02:49,730
And we should be able
to in most cases,
55
00:02:49,730 --> 00:02:52,750
unless there's something
sort of unusual
56
00:02:52,750 --> 00:02:54,910
about the table that
we're loading into
57
00:02:54,910 --> 00:02:57,730
or the data that we have.
58
00:02:57,730 --> 00:03:01,020
So there are a number of files
that are used in a SQL Loader
59
00:03:01,020 --> 00:03:01,770
operation.
60
00:03:01,770 --> 00:03:05,670
So all these have to be
prepared before we run our SQL
61
00:03:05,670 --> 00:03:08,190
Loader, which the statement
itself is quite simple,
62
00:03:08,190 --> 00:03:10,660
but we have to compose
all of these files.
63
00:03:10,660 --> 00:03:13,300
So the first one is the
input data file itself.
64
00:03:13,300 --> 00:03:16,260
So that's going to be the
delimited data or raw data
65
00:03:16,260 --> 00:03:19,230
that we're trying to
load into a table.
66
00:03:19,230 --> 00:03:21,390
The second is the
parameter file,
67
00:03:21,390 --> 00:03:24,780
and that's a file that
just has a location for all
68
00:03:24,780 --> 00:03:28,230
the other files, so the input
data file, the output files,
69
00:03:28,230 --> 00:03:32,580
like the log, and those kind
of things, the control file.
70
00:03:32,580 --> 00:03:36,850
The parameter file is what knows
all about those other files.
71
00:03:36,850 --> 00:03:38,910
And it's actually
the parameter file
72
00:03:38,910 --> 00:03:42,510
that we're going to directly
call from the SQL Loader
73
00:03:42,510 --> 00:03:46,470
application, and then it's
going to find everything else.
74
00:03:46,470 --> 00:03:48,100
And the third is
the control file.
75
00:03:48,100 --> 00:03:49,860
So that's actually
a specification
76
00:03:49,860 --> 00:03:52,990
on how the data is to be loaded.
77
00:03:52,990 --> 00:03:54,120
So let's take a look here.
78
00:03:54,120 --> 00:03:55,890
I've got a little
bit of setup here
79
00:03:55,890 --> 00:03:58,560
already in the
Oracle-based directory.
80
00:03:58,560 --> 00:04:01,350
I've created a
directory called loader.
81
00:04:01,350 --> 00:04:02,370
All right.
82
00:04:02,370 --> 00:04:04,580
Click that.
83
00:04:04,580 --> 00:04:08,750
And then I have a
dept load.dat file.
84
00:04:08,750 --> 00:04:11,730
If we take a look at
that, that's simply
85
00:04:11,730 --> 00:04:13,530
data from the dept table.
86
00:04:13,530 --> 00:04:16,920
So we just poured that
out to a DAT file.
87
00:04:16,920 --> 00:04:20,910
And then, so it's comma
delimited-- three columns,
88
00:04:20,910 --> 00:04:21,990
comma-delimited file.
89
00:04:21,990 --> 00:04:25,110
So that's what we're going to
use for our loader, our load
90
00:04:25,110 --> 00:04:27,140
data.
91
00:04:27,140 --> 00:04:31,490
Let's go into Scott and create
a table to receive this data.
92
00:04:37,460 --> 00:04:40,570
So we'll create a table that's
just like the dept table.
93
00:04:54,510 --> 00:05:00,120
So if we select from
the dept_loader table,
94
00:05:00,120 --> 00:05:01,200
no rows selected.
95
00:05:01,200 --> 00:05:03,070
So we have no data in there yet.
96
00:05:05,760 --> 00:05:08,430
So let's take a look
at the PAR file.
97
00:05:08,430 --> 00:05:11,640
So the PAR file is going to
drive the location of all
98
00:05:11,640 --> 00:05:12,420
the other files.
99
00:05:16,470 --> 00:05:20,610
So in here, we put
the user ID for Scott
100
00:05:20,610 --> 00:05:23,520
and then the name
of the control file.
101
00:05:23,520 --> 00:05:25,320
And we also-- if
we're not running
102
00:05:25,320 --> 00:05:27,510
all of this out
of one directory,
103
00:05:27,510 --> 00:05:31,460
we'll need to put the directory
paths in there as well.
104
00:05:31,460 --> 00:05:34,590
And we have a log
file specified here.
105
00:05:34,590 --> 00:05:35,900
And we have a bad file.
106
00:05:35,900 --> 00:05:39,390
So if there's some reason
that SQL Loader attempts
107
00:05:39,390 --> 00:05:43,710
to load a line of data,
a row, into a table
108
00:05:43,710 --> 00:05:47,370
and that doesn't fit within the
column parameters or whatever,
109
00:05:47,370 --> 00:05:49,470
then it will be listed
in the bad file.
110
00:05:49,470 --> 00:05:52,830
But it will not be
put into the table.
111
00:05:52,830 --> 00:05:54,890
The name of our data file--
112
00:05:54,890 --> 00:05:59,670
so that's the dep_load.dat,
so the data that we're loading
113
00:05:59,670 --> 00:06:03,990
in, and then direct equal true
so that we'll use the direct
114
00:06:03,990 --> 00:06:07,580
path load instead
of conventional.
115
00:06:07,580 --> 00:06:10,170
So let's take a look
at our control file.
116
00:06:10,170 --> 00:06:13,880
So our control file is going
to be the specification on how
117
00:06:13,880 --> 00:06:16,400
the data goes into the table.
118
00:06:16,400 --> 00:06:21,800
So it says load data into table
and the name of the table.
119
00:06:21,800 --> 00:06:24,050
It's doing an
insert as opposed to
120
00:06:24,050 --> 00:06:26,630
an append or other operation.
121
00:06:26,630 --> 00:06:29,270
Fields terminated by--
and then in double quotes,
122
00:06:29,270 --> 00:06:30,830
we put a comma.
123
00:06:30,830 --> 00:06:32,540
So that shows this
that our comma
124
00:06:32,540 --> 00:06:34,800
is our delimiter character--
125
00:06:34,800 --> 00:06:37,760
and then the three
columns that line up
126
00:06:37,760 --> 00:06:39,250
with our dept_loader table.
127
00:06:48,100 --> 00:06:48,790
All right.
128
00:06:48,790 --> 00:06:53,020
So here I am from our command
line in the loader directory
129
00:06:53,020 --> 00:06:57,580
that I've created, and I'm ready
to go ahead and run our SQL
130
00:06:57,580 --> 00:06:59,000
Loader.
131
00:06:59,000 --> 00:07:06,110
So SQL Loader is invoked
using the sqlldr command.
132
00:07:06,110 --> 00:07:08,280
And since we've
constructed all our files,
133
00:07:08,280 --> 00:07:10,790
such as our PAR file
and our control file,
134
00:07:10,790 --> 00:07:18,750
we simply need to say parfile
equal dept_loader.par.
135
00:07:18,750 --> 00:07:19,450
All right.
136
00:07:19,450 --> 00:07:22,400
So it says load completed,
logical record count four.
137
00:07:22,400 --> 00:07:25,000
So it did four rows.
138
00:07:25,000 --> 00:07:27,070
And then we can look
at our director here.
139
00:07:27,070 --> 00:07:30,240
And notice that there's no bad
file that's been generated.
140
00:07:30,240 --> 00:07:32,910
But there is a log
file that tells us
141
00:07:32,910 --> 00:07:37,410
exactly how the data was put
in, which ones were successfully
142
00:07:37,410 --> 00:07:39,660
loaded, and if there were
any rows that weren't loaded
143
00:07:39,660 --> 00:07:43,320
from errors, and those kind
of things, elapsed time,
144
00:07:43,320 --> 00:07:47,120
a very detailed log.
145
00:07:47,120 --> 00:07:52,880
So for our purposes,
let's go in as Scott
146
00:07:52,880 --> 00:07:56,030
and select star
from dept_loader.
147
00:07:56,030 --> 00:07:58,930
And if we recall, it didn't
have any data before.
148
00:07:58,930 --> 00:08:01,820
But it should have
four rows now.
149
00:08:01,820 --> 00:08:02,610
And there they are.
150
00:08:02,610 --> 00:08:04,070
So that's a little
about how to use
151
00:08:04,070 --> 00:08:06,990
SQL Loader to
construct those files
152
00:08:06,990 --> 00:08:10,430
and to load data into tables.
12387
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.