SQL*Loader Concepts. This chapter explains the basic concepts of loading data into an Oracle database with SQL*Loader. This chapter covers the following topics: SQL*Loader Features. SQL*Loader loads data from external files into tables of an Oracle database. It has a powerful data parsing engine that puts little limitation on the format of the data in the datafile. You can use SQL*Loader to do the following: Load data across a network. This means that you can run the SQL*Loader client on a different system from the one that is running the SQL*Loader server. Load data from multiple datafiles during the same load session. Load data into multiple tables during the same load session. Specify the character set of the data. Selectively load data (you can load records based on the records' values). Manipulate the data before loading it, using SQL functions. This sample control file (loader.ctl). One can also specify multiple 'INTO TABLE' clauses in the SQL*Loader control file to load into multiple. The control file tells SQL*Loader how to interpret the. SQL*Loader's log file tells you the state of the tables and indexes and the number of logical. We are allowed to submit only one parameter that should be data file path; SQL * Loader. Generate unique sequential key values in specified columns. Use the operating system's file system to access the datafiles. Load data from disk, tape, or named pipe. Generate sophisticated error reports, which greatly aid troubleshooting. Load arbitrarily complex object- relational data. Use secondary datafiles for loading LOBs and collections. Use either conventional or direct path loading. While conventional path loading is very flexible, direct path loading provides superior loading performance. See Chapter 1. 1. A typical SQL*Loader session takes as input a control file, which controls the behavior of SQL*Loader, and one or more datafiles. The output of SQL*Loader is an Oracle database (where the data is loaded), a log file, a bad file, and potentially, a discard file. An example of the flow of a SQL*Loader session is shown in Figure 6- 1. SQL*Loader Parameters. SQL*Loader is invoked when you specify the sqlldr command and, optionally, parameters that establish session characteristics. In situations where you always use the same parameters for which the values seldom change, it can be more efficient to specify parameters using the following methods, rather than on the command line: Parameters can be grouped together in a parameter file. You could then specify the name of the parameter file on the command line using the PARFILE parameter. Certain parameters can also be specified within the SQL*Loader control file by using the OPTIONS clause. Parameters specified on the command line override any parameter values specified in a parameter file or OPTIONS clause. SQL*Loader Control File. The control file is a text file written in a language that SQL*Loader understands. SQL Loader is a utility that allows you to load data of different format into Oracle. These formats include delimited text file, csv file, etc. SQL LOADER is an Oracle utility used to load data into table given a datafile which has the records that need to be loaded. SQL*Loader takes data file, as well as a. The control file tells SQL*Loader where to find the data, how to parse and interpret the data, where to insert the data, and more. Although not precisely defined, a control file can be said to have three sections. The first section contains session- wide information, for example: Global options such as bindsize, rows, records to skip, and so on. INFILE clauses to specify where the input data is located. Data to be loaded. The second section consists of one or more INTO TABLE blocks. Each of these blocks contains information about the table into which the data is to be loaded, such as the table name and the columns of the table. The third section is optional and, if present, contains input data. Some control file syntax considerations to keep in mind are: The syntax is free- format (statements can extend over multiple lines). It is case insensitive; however, strings enclosed in single or double quotation marks are taken literally, including case. In control file syntax, comments extend from the two hyphens (- -) that mark the beginning of the comment to the end of the line. The optional third section of the control file is interpreted as data rather than as control file syntax; consequently, comments in this section are not supported. The keywords CONSTANT and ZONE have special meaning to SQL*Loader and are therefore reserved. To avoid potential conflicts, Oracle recommends that you do not use either CONSTANT or ZONE as a name for any tables or columns. See Also: Chapter 8 for details about control file syntax and semantics. Input Data and Datafiles. SQL*Loader reads data from one or more files (or operating system equivalents of files) specified in the control file. From SQL*Loader's perspective, the data in the datafile is organized as records. A particular datafile can be in fixed record format, variable record format, or stream record format. The record format can be specified in the control file with the INFILE parameter. If no record format is specified, the default is stream record format. Note. If data is specified inside the control file (that is, INFILE * was specified in the control file), then the data is interpreted in the stream record format with the default record terminator. Fixed Record Format. A file is in fixed record format when all records in a datafile are the same byte length. Although this format is the least flexible, it results in better performance than variable or stream format. Fixed format is also simple to specify. For example. INFILE datafile. The datafile in the example contains five physical records. Assuming that a period (.) indicates a space, the first physical record is . The second record is . Note that newline characters are not required with the fixed record format. Note that the length is always interpreted in bytes, even if character- length semantics are in effect for the file. This is necessary because the file could contain a mix of fields, some of which are processed with character- length semantics and others which are processed with byte- length semantics. See Character- Length Semantics. Example 6- 1 Loading Data in Fixed Record Format. This format provides some added flexibility over the fixed record format and a performance advantage over the stream record format. For example, you can specify a datafile that is to be interpreted as being in variable record format as follows. INFILE . If n is not specified, SQL*Loader assumes a length of 5 bytes. Specifying n larger than 4. Example 6- 2 shows a control file specification that tells SQL*Loader to look for data in the datafile example. The example. dat datafile consists of three physical records. The first is specified to be 0. Note that newline characters are not required with the variable record format. This example also assumes a single- byte character set for the datafile. The lengths are always interpreted in bytes, even if character- length semantics are in effect for the file. This is necessary because the file could contain a mix of fields, some processed with character- length semantics and others processed with byte- length semantics. See Character- Length Semantics. Example 6- 2 Loading Data in Variable Record Format. Stream record format is the most flexible format, but there can be a negative effect on performance. The specification of a datafile to be interpreted as being in stream record format looks similar to the following. INFILE datafile. However, some nonprintable characters can be specified as ('char. For example: \n indicates a line feed\t indicates a horizontal tab\f indicates a form feed\v indicates a vertical tab\r indicates a carriage return. If the character set specified with the NLS. This is done before SQL*Loader checks for the default record terminator. Hexadecimal strings are assumed to be in the character set of the datafile, so no conversion is performed. On UNIX- based platforms, if no terminator. This means that if you know that one or more records in your datafile has \n embedded in a field, but you want \r\n to be used as the record terminator, you must specify it. Example 6- 3 illustrates loading data in stream record format where the terminator string is specified using a character string, '. The use of the backslash character allows the character string to specify the nonprintable line feed character. Example 6- 3 Loading Data in Stream Record Format. By default a physical record is a logical record, but for added flexibility, SQL*Loader can be instructed to combine a number of physical records into a logical record. SQL*Loader can be instructed to follow one of the following logical record- forming strategies: Combine a fixed number of physical records to form each logical record. Combine physical records into logical records while a certain condition is true. Data Fields. Once a logical record is formed, field setting on the logical record is done. Field setting is a process in which SQL*Loader uses control- file field specifications to determine which parts of logical record data correspond to which control- file fields. It is possible for two or more field specifications to claim the same data. Also, it is possible for a logical record to contain data that is not claimed by any control- file field specification. Most control- file field specifications claim a particular part of the logical record. This mapping takes the following forms: The byte position of the data field's beginning, end, or both, can be specified. This specification form is not the most flexible, but it provides high field- setting performance. The strings delimiting (enclosing and/or terminating) a particular data field can be specified. A delimited data field is assumed to start where the last data field ended, unless the byte position of the start of the data field is specified. The byte offset and/or the length of the data field can be specified. This way each field starts a specified number of bytes from where the last one ended and continues for a specified length. Length- value datatypes can be used. In this case, the first n number of bytes of the data field contain information about how long the rest of the data field is. LOBFILEs and Secondary Datafiles (SDFs)LOB data can be lengthy enough that it makes sense to load it from a LOBFILE. In LOBFILEs, LOB data instances are still considered to be in fields (predetermined size, delimited, length- value), but these fields are not organized into records (the concept of a record does not exist within LOBFILEs). SQL*Loader Log File Reference. When SQL*Loader begins execution, it creates a log file. The log file contains a detailed summary of the load. Most of the log file entries are records of successful SQL*Loader execution. However, errors can also cause log file entries. For example, errors found during parsing of the control file appear in the log file. This chapter describes the following sections of a SQL*Loader log file: Header Information. The Header Section contains the following entries: Date of the run. Software version number. For example: SQL*Loader: Release 9. Production on Wed Feb 2. Copyright 2. 00. 2 Oracle Corporation. That is, whether all records were loaded or only those meeting criteria specified in the WHEN clause. INSERT, APPEND, or REPLACE specification. The following column information. Column name. If found in a datafile, the position, length, delimiter, and datatype. See Column Information for a description of these columns. If specified, RECNUM, SEQUENCE, CONSTANT, or EXPRESSIONIf specified, DEFAULTIF or NULLIFFor example: Table EMP, loaded from every logical record. It gives the maximum size of the field, including the size of any embedded length fields. The size will be different with byte- length semantics versus character- length semantics. For example, for VARCHAR(2,1. For VARCHAR(2,1. 0) with character- length semantics, the length is calculated using the maximum size, in bytes, of a character in the datafile character set. For fields that do not have a specified maximum length, an asterisk (*) is written in the Length column. Delimiter. The delimiters are displayed under the headings, Term (for terminated by) and Encl (for enclosed by). If the delimiter is optional, it is preceded by O and is displayed within parentheses. Datatype. The datatype is displayed as specified in the control file. If the SQL*Loader control file contains any directives for loading datetime and interval datatypes, then the log file contains the parameter DATE, DATETIME, or INTERVAL under the Datatype heading. If applicable, the parameter DATE, DATETIME, or INTERVAL is followed by the corresponding mask. For example: Table emp, loaded from every logical record. That is, for all datafiles, the number of records that were. Skipped. Read. Rejected. Discarded. Beginning and ending time of run. Total elapsed time. Total CPU time (includes all file I/O but may not include background Oracle CPU time)For example: Space allocated for bind array: 6. Space allocated for memory less bind array: 6. Total logical records skipped: 0. Total logical records read: 7. Total logical records rejected: 0. Total logical records discarded: 0. Run began on Wed Feb 2. Run ended on Wed Feb 2. Elapsed time was: 0. CPU time was: 0. Oracle Statistics That Are Logged. The statistics that are reported to the log file vary, depending on the load type. For conventional loads and direct loads of a nonpartitioned table, statistics reporting is unchanged from Oracle. For direct loads of a partitioned table, a per- partition statistics section is provided after the table- level statistics section. For a single- partition load, the partition name will be included in the table- level statistics section. Information About Single- Partition Loads. The following information is logged when a single partition is loaded: The table column description includes the partition name. Error messages include the partition name. Statistics listings include the partition name. Statistics for Loading a Table. The following statistics are logged when a table is loaded: Direct path load of a partitioned table reports per- partition statistics. Conventional path load cannot report per- partition statistics. For loading a nonpartitioned table, statistics are unchanged from Oracle. For conventional loads and direct loads of a nonpartitioned table, statistics reporting is unchanged from Oracle. If you request logging, but media recovery is not enabled, the load is not logged. Additional Summary Statistics for Direct Path Loads and Multithreading. For direct path loads, the log contains the following additional data (the numbers in your log file will be different): Column array rows: 2. Stream buffer bytes: 2. See Specifying the Number of Column Array Rows and Size of Stream Buffers for information about the origin of these statistics. Direct path loads on multiple- CPU systems have the option of using multithreading. If multithreading is enabled (the default behavior), the following additional statistics are logged (the numbers in your log will be different): Total stream buffers loaded by SQL*Loader main thread: 1. Total stream buffers loaded by SQL*Loader load thread: 2. See Optimizing Direct Path Loads on Multiple- CPU Systems for more information about multithreading. Log File Created When EXTERNAL. To do this, set the EXTERNAL. The actual load can be done later without the use of SQL*Loader by executing these statements in SQL*Plus. To generate an example of the log file created when using EXTERNAL.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
January 2017
Categories |