Oracle sql loader 2001.pdf

(5206 KB) Pobierz
Oracle sql*loader
,AUTHOR.COLO.14826 Page 1 Sunday, June 17, 2001 6:53 PM
About the Authors
Jonathan Gennick is a writer and editor. His writing career began in 1997 when he
coauthored Teach Yourself PL/SQL in 21 Days . Since then, he has written several
O’Reilly books, including Oracle SQL*Plus: The Definitive Guide , Oracle SQL*Plus
Pocket Reference , and Oracle Net8 Configuration and Troubleshooting . He has also
edited a number of books for O’Reilly and other publishers, and he recently joined
O’Reilly as an associate editor, specializing in Oracle books. Jonathan was formerly
a manager in KPMG’s Public Services Systems Integration practice, where he was
also the lead database administrator for the utilities group working out of KPMG’s
Detroit office. He has more than a decade of experience with relational databases.
Jonathan is a member of MENSA, and he holds a Bachelor of Arts degree in Infor-
mation and Computer Science from Andrews University in Berrien Springs,
Michigan. He currently resides in Munising, Michigan, with his wife Donna and
their two children: twelve-year-old Jenny, who often wishes her father wouldn’t
spend quite so much time writing, and five-year-old Jeff, who has never seen it
any other way. You can reach Jonathan by email at jonathan@gennick.com . You
can also visit Jonathan’s web site at http://gennick.com .
Sanjay Mishra is a certified Oracle database administrator with more than nine
years of IT experience. For the past six years, he has been involved in the design,
architecture, and implementation of many mission-critical and decision support
databases. He has worked extensively in the areas of database architecture, data-
base management, backup/recovery, disaster planning, performance tuning,
Oracle Parallel Server, and parallel execution. He has a Bachelor of Science degree
in Electrical Engineering and a Master of Engineering degree in Systems Science
and Automation. He is the coauthor of Oracle Parallel Processing (O’Reilly & Asso-
ciates) and can be reached at sanjay_mishra@i2.com .
Colophon
Our look is the result of reader comments, our own experimentation, and feedback
from distribution channels. Distinctive covers complement our distinctive approach
to technical topics, breathing personality and life into potentially dry subjects.
The animal on the cover of Oracle SQL*Loader: The Definitive Guide is a scarab
beetle. There are nearly 30,000 members of the scarab beetle family, and over
1,200 in North America alone. This large, heavy-bodied beetle is classified in the
order Coleoptera , family Scarabaeidae . Many scarab beetles are brightly colored,
and some are iridescent. In North America, the largest scarabs are the Hercules
22908579.142.png 22908579.153.png 22908579.164.png 22908579.175.png 22908579.001.png 22908579.012.png 22908579.023.png 22908579.034.png 22908579.045.png 22908579.056.png 22908579.067.png 22908579.078.png 22908579.089.png 22908579.100.png 22908579.102.png 22908579.103.png 22908579.104.png 22908579.105.png 22908579.106.png 22908579.107.png 22908579.108.png 22908579.109.png 22908579.110.png 22908579.111.png 22908579.112.png 22908579.113.png 22908579.114.png 22908579.115.png 22908579.116.png 22908579.117.png 22908579.118.png 22908579.119.png 22908579.120.png 22908579.121.png 22908579.122.png 22908579.123.png 22908579.124.png
,AUTHOR.COLO.14826 Page 2 Sunday, June 17, 2001 6:53 PM
beetle and the closely related elephant and rhinoceros beetles. The males of these
species have prominent horns.
Many scarabs are scavengers, living on decaying vegetation and animal dung. They
are consider efficient recyclers and valuable for reducing disease-breeding waste.
Some of the scavengers of the scarab family use their front legs to gather dung and
roll it into a ball. They carry the ball underground and use it as food and a place to
lay their eggs. The Mediterranean black scarab’s apparently magical ability to repro-
duce from mud and decaying organic materials led the ancient Egyptians to
associate the scarab with resurrection and immortality. The beetles were consid-
ered sacred, and representations in stone and metal were buried with mummies.
A member of the North American scarab family plays a key role in Edgar Allen
Poe’s story “The Gold-Bug.” In his search of Sullivan’s Island, South Carolina, a
scarab beetle is William Legrand’s mysterious guide to the buried treasure of
Captian Kidd.
Colleen Gorman was the production editor and the copyeditor for Oracle
SQL*Loader: The Definitive Guide . Sarah Jane Shangraw and Linley Dolby provided
quality control, and Leanne Soylemez was the proofreader. John Bickelhaupt
wrote the index.
Ellie Volckhausen designed the cover of this book, based on a series design by
Edie Freedman. The cover image is from Cuvier’s Animals . Emma Colby produced
the cover layout with QuarkXPress 4.1 using Adobe’s ITC Garamond font.
Melanie Wang designed the interior layout based on a series design by Nancy
Priest. Anne-Marie Vaduva converted the files from Microsoft Word to FrameMaker
5.5.6 using tools created by Mike Sierra. The text and heading fonts are ITC Gara-
mond Light and Garamond Book; the code font is Constant Willison. The
illustrations that appear in the book were produced by Robert Romano and
Jessamyn Read using Macromedia FreeHand 9 and Adobe Photoshop 6. This colo-
phon was written by Colleen Gorman.
Whenever possible, our books use a durable and flexible lay-flat binding. If the
page count exceeds this binding’s limit, perfect binding is used.
22908579.125.png 22908579.126.png 22908579.127.png 22908579.128.png 22908579.129.png 22908579.130.png 22908579.131.png 22908579.132.png 22908579.133.png 22908579.134.png 22908579.135.png 22908579.136.png 22908579.137.png 22908579.138.png 22908579.139.png 22908579.140.png 22908579.141.png 22908579.143.png 22908579.144.png 22908579.145.png 22908579.146.png 22908579.147.png 22908579.148.png 22908579.149.png 22908579.150.png 22908579.151.png 22908579.152.png 22908579.154.png 22908579.155.png 22908579.156.png 22908579.157.png 22908579.158.png 22908579.159.png 22908579.160.png 22908579.161.png 22908579.162.png 22908579.163.png
,sql_loaderTOC.fm.28101 Page vii Wednesday, April 11, 2001 1:48 PM
Table of Contents
Preface ..................................................................................................................... xi
1. Introduction to SQL*Loader .................................................................. 1
The SQL*Loader Environment ......................................................................... 2
A Short SQL*Loader Example .......................................................................... 4
SQL*Loader’s Capabilities .............................................................................. 11
Issues when Loading Data ............................................................................. 11
Invoking SQL*Loader ..................................................................................... 14
2. The Mysterious Control File ................................................................ 22
Syntax Rules ................................................................................................... 22
The LOAD Statement ..................................................................................... 28
Command-Line Parameters in the Control File ............................................ 43
Placing Data in the Control File .................................................................... 45
3. Fields and Datatypes ............................................................................. 47
Field Specifications ........................................................................................ 47
Datatypes ........................................................................................................ 59
4. Loading from Fixed-Width Files ........................................................ 78
Common Datatypes Encountered ................................................................. 79
Specifying Field Positions .............................................................................. 79
Handling Anomalous Data ............................................................................ 83
Concatenating Records .................................................................................. 96
Nesting Delimited Fields .............................................................................. 103
vii
Oracle 8i Internal Services for Waits, Latches, Locks, and Memory, eMatter Edition
Copyright © 2001 O’Reilly & Associates, Inc. All rights reserved.
22908579.165.png 22908579.166.png 22908579.167.png 22908579.168.png 22908579.169.png 22908579.170.png 22908579.171.png 22908579.172.png 22908579.173.png 22908579.174.png 22908579.176.png 22908579.177.png 22908579.178.png 22908579.179.png 22908579.180.png 22908579.181.png 22908579.182.png 22908579.183.png 22908579.184.png 22908579.185.png 22908579.002.png 22908579.003.png 22908579.004.png 22908579.005.png 22908579.006.png 22908579.007.png 22908579.008.png 22908579.009.png 22908579.010.png 22908579.011.png 22908579.013.png 22908579.014.png 22908579.015.png 22908579.016.png 22908579.017.png 22908579.018.png 22908579.019.png
,sql_loaderTOC.fm.28101 Page viii Wednesday, April 11, 2001 1:48 PM
viii
Table of Contents
5. Loading Delimited Data .................................................................... 107
Common Datatypes Encountered ............................................................... 107
Example Data ............................................................................................... 108
Using Delimiters to Identify Fields .............................................................. 108
Common Issues with Delimited Data ......................................................... 118
Concatenating Records ................................................................................ 124
Handling Nested Fields ................................................................................ 127
6. Recovering from Failure .................................................................... 130
Deleting and Starting Over .......................................................................... 131
Restarting a Conventional Path Load .......................................................... 132
Restarting a Direct Path Load ...................................................................... 136
7. Validating and Selectively Loading Data .................................... 141
Handling Rejected Records .......................................................................... 141
Selectively Loading Data .............................................................................. 146
8. Transforming Data During a Load ............................................... 152
Using Oracle’s Built-in SQL Functions ........................................................ 152
Writing Your Own Functions ...................................................................... 156
Passing Data Through Work Tables ........................................................... 158
Using Triggers .............................................................................................. 159
Performing Character Set Conversion ......................................................... 161
9. Transaction Size and Performance Issues .................................. 167
Transaction Processing in SQL*Loader ....................................................... 167
Commit Frequency and Load Performance ................................................ 168
Commit Frequency and Rollback Segments ............................................... 175
Performance Improvement Guidelines ....................................................... 179
10. Direct Path Loads .................................................................................. 182
What is the Direct Path? ............................................................................... 182
Performing Direct Path Loads ..................................................................... 184
Data Saves .................................................................................................... 196
Loading Data Fields Greater than 64K ........................................................ 197
UNRECOVERABLE Loads ............................................................................ 198
Parallel Data Loading ................................................................................... 199
11. Loading Large Objects ........................................................................ 205
About Large Objects .................................................................................... 205
Considerations when Loading LOBs ........................................................... 208
Oracle 8i Internal Services for Waits, Latches, Locks, and Memory, eMatter Edition
Copyright © 2001 O’Reilly & Associates, Inc. All rights reserved.
22908579.020.png 22908579.021.png 22908579.022.png 22908579.024.png 22908579.025.png 22908579.026.png 22908579.027.png 22908579.028.png 22908579.029.png 22908579.030.png 22908579.031.png 22908579.032.png 22908579.033.png 22908579.035.png 22908579.036.png 22908579.037.png 22908579.038.png 22908579.039.png 22908579.040.png 22908579.041.png 22908579.042.png 22908579.043.png 22908579.044.png 22908579.046.png 22908579.047.png 22908579.048.png 22908579.049.png 22908579.050.png 22908579.051.png 22908579.052.png 22908579.053.png 22908579.054.png 22908579.055.png 22908579.057.png 22908579.058.png 22908579.059.png 22908579.060.png
,sql_loaderTOC.fm.28101 Page ix Wednesday, April 11, 2001 1:48 PM
Table of Contents
ix
Loading Inline LOBs .................................................................................... 210
Loading LOBs from External Data Files ...................................................... 212
Loading BFILEs ............................................................................................. 217
12. Loading Objects and Collections .................................................... 221
Loading Object Tables and Columns .......................................................... 221
Loading Collections ...................................................................................... 225
Using NULLIF and DEFAULTIF with an Object or a Collection ................ 240
Index .................................................................................................................... 243
Oracle 8i Internal Services for Waits, Latches, Locks, and Memory, eMatter Edition
Copyright © 2001 O’Reilly & Associates, Inc. All rights reserved.
22908579.061.png 22908579.062.png 22908579.063.png 22908579.064.png 22908579.065.png 22908579.066.png 22908579.068.png 22908579.069.png 22908579.070.png 22908579.071.png 22908579.072.png 22908579.073.png 22908579.074.png 22908579.075.png 22908579.076.png 22908579.077.png 22908579.079.png 22908579.080.png 22908579.081.png 22908579.082.png 22908579.083.png 22908579.084.png 22908579.085.png 22908579.086.png 22908579.087.png 22908579.088.png 22908579.090.png 22908579.091.png 22908579.092.png 22908579.093.png 22908579.094.png 22908579.095.png 22908579.096.png 22908579.097.png 22908579.098.png 22908579.099.png 22908579.101.png
Zgłoś jeśli naruszono regulamin