Sample ctl file for sqlldr


















It would be very kind if you help me as you have done it in recent past. So I want to know the following questions to be answered:.

Describe in Detail the following: I: Trailing by nullcols. II: Optionally closed by. I have updated oracle version to 11g. But while executing vb file it is taking 10g version. Please tell me where can i get path to oracle while executing vb file. Hi Ramesh, I am trying to load the fixed width file to temp table using control file but getting below error:. Save my name, email, and website in this browser for the next time I comment.

Notify me of followup comments via e-mail. All rights reserved Terms of Service. If you are using Oracle database, at some point you might have to deal with uploading data to the tables from a text file. Nice June 25, , am. Thanks for the article. Great Post.. Prasath June 25, , pm. This is Nice…. Lin Thein Naing July 13, , am. Really awesome!!!! Appreciate ….

Manjula July 23, , pm. Prithviraj July 30, , am. Manjula: Ramesh has explained answer to your question in example 8. Rohit K August 5, , am. Thanks in advance! Regards, Rohit. Prithviraj August 6, , am. Rohit K August 6, , am. Thank You Prithviraj. We can do it using a control file this way. Thank You once again. Regards, Rohit K. SantoshCA September 4, , am. Jurgen October 26, , am. Kind regards, Jurgen. Mahes Tripathi November 6, , am. Hi All, I have a flatfile notepad , which has data not in order, fields separated by space, that too not orderly separated.

Thanks souji. Kenneth Y January 10, , pm. Dhawal Limbuwala January 24, , am. Imteyaz March 14, , pm. Naveen March 29, , pm. Great Explanation , simple and clear. Naresh April 5, , am. Can anyone tell me how to load it…. Ashok May 13, , pm. Praveen Kumar July 23, , pm. The article is very good and easily understandable.

Nice explanation…, thank you so much! Muhd Islam August 24, , pm. Gauthama P August 28, , am. To declare a file named mydata. If you have specified that a bad file is to be created, then the following applies:. If one or more records are rejected, then the bad file is created and the rejected records are logged. If the bad file is created, then it overwrites any existing file with the same name; ensure that you do not overwrite a file you want to retain.

If you do not specify a name for the bad file, then the name defaults to the name of the data file with an extension or file type of. You can also specify the bad file from the command line with the BAD parameter described in "Command-Line Parameters". A file name specified on the command line is associated with the first INFILE clause in the control file, overriding any bad file that may have been specified as part of that clause.

The bad file is created in the same record and file format as the data file so that you can reload the data after you correct it. For data files in stream record format, the record terminator that is found in the data file is also used in the bad file. The filename parameter specifies a valid file name specification for your platform. To specify a bad file with file name sample and default file extension or file type of.

To specify a bad file with file name bad and file extension or file type of. If there is an error loading a LOB, then the row is not rejected.

Rather, the LOB column is left empty not null with a length of zero 0 bytes. If the data can be evaluated according to the WHEN clause criteria even with unbalanced delimiters , then it is either inserted or rejected.

Neither a conventional path nor a direct path load will write a row to any table if it is rejected because of reason number 2 in the previous list. A conventional path load will not write a row to any tables if reason number 1 or 3 in the previous list is violated for any one table. The row is rejected for that table and written to the reject file. In a conventional path load, if the data file has a record that is being loaded into multiple tables and that record is rejected from at least one of the tables, then that record is not loaded into any of the tables.

The log file indicates the Oracle error for each rejected record. Case study 4 demonstrates rejected records. The records contained in this file are called discarded records. Discarded records do not satisfy any of the WHEN clauses specified in the control file. These records differ from rejected records. Discarded records do not necessarily have any bad data. No insert is attempted on a discarded record. You have specified a discard file name and one or more records fail to satisfy all of the WHEN clauses specified in the control file.

Be aware that if the discard file is created, then it overwrites any existing file with the same name. You can specify the discard file directly by specifying its name, or indirectly by specifying the maximum number of discards. The discard file is created in the same record and file format as the data file.

For data files in stream record format, the same record terminator that is found in the data file is also used in the discard file.

The default file name is the name of the data file, and the default file extension or file type is.

A discard file name specified on the command line overrides one specified in the control file. If a discard file with that name already exists, then it is either overwritten or a new version is created, depending on your operating system.

A file name specified on the command line overrides any discard file that you may have specified in the control file. The following list shows different ways you can specify a name for the discard file from within the control file:. To specify a discard file with file name circular and default file extension or file type of. To specify a discard file named notappl with the file extension or file type of. To specify a full path to the discard file forget. An attempt is made to insert every record into such a table.

Therefore, records may be rejected, but none are discarded. Case study 7, Extracting Data from a Formatted Report, provides an example of using a discard file. When the discard limit is reached, processing of the data file terminates and continues with the next data file, if one exists. You can specify a different number of discards for each data file. Or, if you specify the number of discards only once, then the maximum number of discards specified applies to all files.

The following sections provide a brief introduction to some of the supported character encoding schemes. Multibyte character sets support Asian languages. Data can be loaded in multibyte format, and database object names fields, tables, and so on can be specified with multibyte characters. In the control file, comments and object names can also use multibyte characters. Unicode is a universal encoded character set that supports storage of information from most languages in a single character set.

Unicode provides a unique code value for every character, regardless of the platform, program, or language. A character in UTF-8 can be 1 byte, 2 bytes, or 3 bytes long. Multibyte fixed-width character sets for example, AL16UTF16 are not supported as the database character set. This alternative character set is called the database national character set. Only Unicode character sets are supported as the database national character set.

However, the Oracle database supports only UTF encoding with big-endian byte ordering AL16UTF16 and only as a database national character set, not as a database character set. When data character set conversion is required, the target character set should be a superset of the source data file character set. Otherwise, characters that have no equivalent in the target character set are converted to replacement characters, often a default character such as a question mark?

This causes loss of data. If they are specified in bytes, and data character set conversion is required, then the converted values may take more bytes than the source values if the target character set uses more bytes than the source character set for any character that is converted. This will result in the following error message being reported if the larger target value exceeds the size of the database column:.

You can avoid this problem by specifying the database column size in characters and also by using character sizes in the control file to describe the data. Another way to avoid this problem is to ensure that the maximum column size is large enough, in bytes, to hold the converted value. Oracle Database Concepts f or more information about character-length semantics in the database. Oracle Database Globalization Support Guide. Rows might be rejected because a field is too large for the database column, but in reality the field is not too large.

A load might be abnormally terminated without any rows being loaded, when only the field that really was too large should have been rejected. Normally, the specified name must be the name of an Oracle-supported character set. However, because you are allowed to set up data using the byte order of the system where you create the data file, the data in the data file can be either big-endian or little-endian.

Therefore, a different character set name UTF16 is used. All primary data files are assumed to be in the same character set. Oracle Database Globalization Support Guide for more information about the names of the supported character sets. If the control file character set is different from the data file character set, then keep the following issue in mind. To ensure that the specifications are correct, you may prefer to specify hexadecimal strings, rather than character string values.

If hexadecimal strings are used with a data file in the UTF Unicode encoding, then the byte order is different on a big-endian versus a little-endian system. For example, "," comma in UTF on a big-endian system is X'c'.

On a little-endian system it is X'2c00'. This allows the same syntax to be used in the control file on both a big-endian and a little-endian system. For example, the specification CHAR 10 in the control file can mean 10 bytes or 10 characters. These are equivalent if the data file uses a single-byte character set.

However, they are often different if the data file uses a multibyte character set. To avoid insertion errors caused by expansion of character strings during character set conversion, use character-length semantics in both the data file and the target database columns.

Byte-length semantics are the default for all data files except those that use the UTF16 character set which uses character-length semantics by default. The following datatypes use byte-length semantics even if character-length semantics are being used for the data file, because the data is binary, or is in a special binary-encoded form in the case of ZONED and DECIMAL :.

This is necessary to handle data files that have a mix of data of different datatypes, some of which use character-length semantics, and some of which use byte-length semantics. The SMALLINT length field takes up a certain number of bytes depending on the system usually 2 bytes , but its value indicates the length of the character string in characters.

Character-length semantics in the data file can be used independent of whether character-length semantics are used for the database columns. Therefore, the data file and the database columns can use either the same or different length semantics. The fastest way to load shift-sensitive character data is to use fixed-position fields without delimiters.

To improve performance, remember the following points:. If blanks are not preserved and multibyte-blank-checking is required, then a slower path is used. This can happen when the shift-in byte is the last byte of a field after single-byte blank stripping is performed.

Loads are interrupted and discontinued for several reasons. DATA specifies the name of the datafile containing the data to be loaded.

If you do not specify a file extension or file type, the default is. If you specify a datafile on the command line and also specify datafiles in the control file with INFILE, the data specified on the command line is processed first. The first datafile specified in the control file is ignored. All other datafiles specified in the control file are processed.

If you specify a file processing option when loading data from the control file, a warning message will be issued. Default: Enabled for elements. To completely disable the date cache feature, set it to 0. Every table has its own date cache, if one is needed.

A date cache is created only if at least one date or timestamp value is loaded that requires datatype conversion in order to be stored in the table.

The date cache feature is only available for direct path loads. It is enabled by default. The default date cache size is elements. If the default size is used and the number of unique input values loaded exceeds , then the date cache feature is automatically disabled for that table.

However, if you override the default and specify a nonzero date cache size and that size is exceeded, then the cache is not disabled. You can use the date cache statistics entries, hits, and misses contained in the log file to tune the size of the cache for future similar loads.

DIRECT specifies the data path, that is, the load method to use, either conventional path or direct path. A value of true specifies a direct path load. A value of false specifies a conventional path load. A discard file filename specified on the command line becomes the discard file associated with the first INFILE statement in the control file.

If the discard file filename is specified also in the control file, the command-line value overrides it. To stop on the first discarded record, specify one 1. To specify that all errors be allowed, use a very high number. Any data inserted up that point, however, is committed.

Therefore, multitable loads do not terminate immediately if errors exceed the error limit. There are three possible values:. It means the load is performed using either conventional or direct path mode. These SQL statements can be edited and customized. However, if any of the SQL statements returns an error, then the attempt to load stops.

Statements are placed in the log file as they are executed. If hexadecimal strings are used with a datafile in the UTF Unicode encoding, the byte order is different on a big endian versus a little endian system. For example, "," comma in UTF on a big endian system is X'c'. On a little endian system it is X'2c00'. This allows the same syntax to be used in the control file on both a big endian and a little endian system.

For example, the specification CHAR 10 in the control file can mean 10 bytes or 10 characters. These are equivalent if the datafile uses a single-byte character set. However, they are often different if the datafile uses a multibyte character set. To avoid insertion errors caused by expansion of character strings during character set conversion, use character-length semantics in both the datafile and the target database columns.

Byte-length semantics are the default for all datafiles except those that use the UTF16 character set which uses character-length semantics by default. It is possible to specify different length semantics for different input datafiles. The following datatypes use byte-length semantics even if character-length semantics are being used for the datafile, because the data is binary, or is in a special binary-encoded form in the case of ZONED and DECIMAL:.

This is necessary to handle datafiles that have a mix of data of different datatypes, some of which use character-length semantics, and some of which use byte-length semantics. The SMALLINT length field takes up a certain number of bytes depending on the system usually 2 bytes , but its value indicates the length of the character string in characters.

Character-length semantics in the datafile can be used independent of whether or not character-length semantics are used for the database columns. Therefore, the datafile and the database columns can use either the same or different length semantics.

Loads are interrupted and discontinued for a number of reasons. Additionally, when an interrupted load is continued, the use and value of the SKIP parameter can vary depending on the particular case. The following sections explain the possible scenarios. In a conventional path load, data is committed after all data in the bind array is loaded into all tables.

If the load is discontinued, only the rows that were processed up to the time of the last commit operation are loaded. There is no partial commit of data. In a direct path load, the behavior of a discontinued load varies depending on the reason the load was discontinued.

This means that when you continue the load, the value you specify for the SKIP parameter may be different for different tables. If a fatal error is encountered, the load is stopped and no data is saved unless ROWS was specified at the beginning of the load.

In that case, all data that was previously committed is saved. This means that the value of the SKIP parameter will be the same for all tables.

When a load is discontinued, any data already loaded remains in the tables, and the tables are left in a valid state. If the conventional path is used, all indexes are left in a valid state. If the direct path load method is used, any indexes that run out of space are left in an unusable state. You must drop these indexes before the load can continue.

You can re-create the indexes either before continuing or after the load completes. Other indexes are valid if no other errors occurred. See Indexes Left in an Unusable State for other reasons why an index might be left in an unusable state. Use this information to resume the load where it left off. To continue the discontinued load, use the SKIP parameter to specify the number of logical records that have already been processed by the previous load.

At the time the load is discontinued, the value for SKIP is written to the log file in a message similar to the following:. This message specifying the value of the SKIP parameter is preceded by a message indicating why the load was discontinued. Note that for multiple-table loads, the value of the SKIP parameter is displayed only if it is the same for all tables. However, there may still be situations in which you may want to do so. At some point, when you want to combine those multiple physical records back into one logical record, you can use one of the following clauses, depending on your data:.

In the following example, integer specifies the number of physical records to combine. For example, two records might be combined if a pound sign were in byte position 80 of the first record. If any other character were there, the second record would not be added to the first.

If the condition is true in the current record, then the next physical record is read and concatenated to the current physical record, continuing until the condition is false. If the condition is false, then the current physical record becomes the last physical record of the current logical record.

THIS is the default. If the condition is true in the next record, then the current physical record is concatenated to the current logical record, continuing until the condition is false. For the equal operator, the field and comparison string must match exactly for the condition to be true.

For the not equal operator, they may differ in any character. This test is similar to THIS, but the test is always against the last nonblank character. If the last nonblank character in the current physical record meets the test, then the next physical record is read and concatenated to the current physical record, continuing until the condition is false. If the condition is false in the current record, then the current physical record is the last physical record of the current logical record.

Specifies the starting and ending column numbers in the physical record. Column numbers start with 1. Either a hyphen or a colon is acceptable start - end or start : end.

If you omit end, the length of the continuation field is the length of the byte string or character string. If you use end, and the length of the resulting continuation field is not the same as that of the byte string or the character string, the shorter one is padded.

Character strings are padded with blanks, hexadecimal strings with zeros. A string of characters to be compared to the continuation field defined by start and end, according to the operator.

The string must be enclosed in double or single quotation marks. The comparison is made character by character, blank padding on the right if necessary. A string of bytes in hexadecimal format used in the same way as str.

X'1FB would represent the three bytes with values 1F, B0, and 33 hexadecimal. The default is to exclude them. This is the only time you refer to positions in physical records.

All other references are to logical records. That is, data values are allowed to span the records with no extra characters continuation characters in the middle.

Assume that you have physical records 14 bytes long and that a period represents a space:. Assume that you have the same physical records as in Example Note that columns 1 and 2 are not removed from the physical records when the logical records are assembled. Therefore, the logical records are assembled as follows the same results as for Example It defines the relationship between records in the datafile and tables in the database.

The specification of fields and datatypes is described in later sections. The table must already exist. If the table is not in the user's schema, then the user must either use a synonym to reference the table or include the schema name as part of the table name for example, scott. That method overrides the global table-loading method. The following sections discuss using these options to load data into empty and nonempty tables.

It requires the table to be empty before loading. After the rows are successfully deleted, a commit is issued.



0コメント

  • 1000 / 1000