|
|
UNLOAD - Unloading Data
You use the
UNLOADcommand to unload data and/or definitions from a Mimer SQL database to a file.Syntax
Usage
Any ODBC-based SQL interpreter or with the
MIMLOADprogram.For information on
MIMLOAD, see EXPTOLOAD - Convert Old Format Export Files.Description
The
UNLOADcommand generates data and/or definitions and places the result in a single file. You can use the optionsALL(default),DEFINITIONSorDATAto specify the information you want.When generating the data and definitions, a data description header is created before information is written to the file. If information from several tables is generated, a data description header for each data section is created.
A data description header contains escaping information and column separator information. For more information, see Data Description Headers and Files.
Data Escape Mode
UNLOADgenerates data in escaped mode. This means that the data description header includes thedata escape modeoption.When using
data escape mode, the following characteristics are enabled, from theUNLOADperspective:
- Data from a specific table is ended by the escape sequence '
\_' to mark end-of-table.NULLvalues are indicated by the escape sequence '\-'.BLOBandBINARYcolumns are unloaded in HEX code with a leading '\x' escape sequence for each byte.BLOB,CLOBandNCLOBcolumns are unloaded so that the value length is given in front of the value as in the followingCLOBexample: '11:Abracadabra'- For
CHAR,NCHAR,CLOBandNCLOBcolumns, the escape sequence '\x' is used only when there is binary data, such as ISO control codes, new-line characters, etc. in the data.- The '
\u' escape sequence is used only when Unicode data is to be written to Latin1 files.For information on escape sequences, see Escape Character Sequences.
The STDOUT Option
When you use the
STDOUToption, generated output is written to the standard output stream. See Using STDIN/STDOUT/STDERR.The AS Option
By using the
ASoption together with a file name specification, you can select the character set of the generated file. You can choose:LATIN1,UTF8,UTF16,UTF16BE,UTF16LE,UTF32,UTF32BEorUTF32LE.
UTFxxBEandUTFxxLEmeansUTFxxformat with big or little endian byte order.UTFxxwithout endian notion means that the common endian for the current platform is assumed.The character set used, if you do not use the
ASoption, is the default used in your host operating system.For more information, see File Format Specifications.
The LOG Option
You can generate a log of the operation using the
LOGoption. The log file will include warnings and progress information about the operation. If you do not use theLOGoption, warnings and progress information are suppressed.The STDERR Option
When you use the
LOG STDERRoption, informational messages are written to the standard error stream. See Using STDIN/STDOUT/STDERR.The USING and FROM Options
To specify the information to be unloaded, you use the
USINGorFROMoptions.With the
USINGoption, an SQL statement, such asSELECT * FROM T1; or aCALLto a procedure with parameter markers (?) for output parameters only, can be used to specify the source.By using an SQL statement to form the source for the export operation, there are many possibilities available to format and customize the output.
With the
FROMoption, one or several databanks, tables or schemas can be used to form the source for the export operation. If using theFROM CURRENT USERoption, the current ident is exported.If tables are joined in the SQL statement used, and definitions are generated, a new table that is a reflection of the result of the join is defined. The default name of the new table is
table1.Error Management
The
UNLOADcommand runs until a major error is encountered. Minor problems are reported as warnings ifLOGis enabled. If a fatal error occurs, an error message is displayed and the operation is aborted.Examples
The following example will export the table
details, with all related definitions, to a file:UNLOAD DEFINITIONS TO 'table_t.def' FROM TABLE details;The following example will export the
CREATEstatement for tabledetailstogether with all data in the table to a file inUTF16format. A log file is used:UNLOAD TO 'table_t.all' AS UTF16 LOG 'table_t.log' USING SELECT * FROM details;Data Description Headers and Files
Data description headers and files are used to describe the data that follows.
The following table describes data description header elements:
As shown in the table above, the characters used to specify column separators, text qualifiers and
NULLindicators must be enclosed in single quotes. If you use a single quote to specify a column separator, text qualifier orNULLindicator, you must enter it twice, for example, you would specify a single quote as a column separator as''''.Data Description Header Examples
For data unloaded from a Mimer SQL database using
UNLOAD, the data description header generated could look as follows:#data escape mode using insert into t (c) values (?);The example above implies the following for
LOAD:
- The column separator is the comma character (default).
- Text strings are presumed to be unqualified or qualified with the double quote character.
- Data escaping is assumed (see the table below).
- The
USINGstatement in the header will be used if noUSINGclause is given in theLOADstatement.The following is another example of a data description header where all optional elements mentioned above, except
data escape mode, are used:#data column separator ':' text qualifier '!' null indicator '§' using insert into t1 (c1,c2,c3) values (?,?,?);In the example above, the table
t1and the columnsc1,c2andc3are supposed to exist when starting the data load. Specific characters forcolumn separator,text qualifierandnull indicatorare defined.Escape Character Sequences
If data escape mode is specified, the back-slash character (
\) is used as the escape character. The character following the escape character can be one of 'x', 'u', '-' or '_'. See the following table for a description of valid escape character sequences:Note: If you do not use data escape mode, end of file is treated as end of table. This means that such a data file only can contain data for one table.
File Format Specifications
The various file formats that can be used are described briefly in the following table:
File Format
Description
latin1 ISO 8859-1, i.e. ISO's 8-bit single-byte coded graphic character set for Western languages.utf816
utf
utf32 Unicode Transformation Formats, standard character encoding schemes in accordance with ISO 10646.For more information, see http://www.unicode.orgutf16beutf16leutf32beutf32le
|
Mimer Information Technology AB Voice: +46 18 780 92 00 Fax: +46 18 780 92 40 info@mimer.se |
|
|