Data movement in DB2 (1)

Source: Internet
Author: User

The so-called data movement in DB2 includes:
1. Import Data)
2. Data Export (Export)
3. Load)

Both import and load use DB2 commands to save data in files of a certain format to tables in the database.
Export refers to saving the data in the table of the DB2 database to a file of a certain format.

The role of data movement:

To transfer data between different database management systems, data movement is usually the most practical method, because any database management system supports common file formats, this universal interface makes it easy to transfer data between different systems.

Among the three commands, Export is the simplest. Because data is transferred from a table to a file, there is usually no error or illegal data.

Before explaining commands, we will first introduce the file formats. There are four file formats for DB2 data movement:
1. ASC -- a non-bounded ASCII file, which is an ASCII plain stream. The rows in the data stream are separated by line delimiters, and each column in the row is defined by the start and end positions. For example:

10 Head Office 160 initialize ate New York
15 New England 50 Eastern Boston
20 Mid Atlantic 10 Eastern Washington
38 South Atlantic 30 Eastern Atlantic
42 Great Lakes 100 Midwest Chicago
51 Plains 140 Midwest Dallas
66 Pacific 270 Western San Francisco
84 Mountain 290 Western Denver

2. DEL -- specifies an ASCII file, which is also an ASCII transfer stream. The rows in the data stream are separated by line delimiters, and the column values in the rows are separated by column delimiters. File Type modifiers can be used to modify the default values of these delimiters. For example:

10, "Head Office", 160, "initialize ate", "New York"
15, "New England", 50, "Eastern", "Boston"
20, "Mid Atlantic", 10, "Eastern", "Washington"
38, "South Atlantic", 30, "Eastern", "Atlantic"
42, "Great Lakes", 100, "Midwest", "Chicago"
51, "Plains", 140, "Midwest", "Dallas"
66, "Pacific", 270, "Western", "San Francisco"
84, "Mountain", 290, "Western", "Denver"

3. WSF -- (work sheet format) is a worksheet format used for data exchange with the Lotus series software.

4. PC/IXF -- an adapted version of the integrated Exchange Format (IXF) data Exchange architecture, which consists of records with Variable Length of some columns, it includes the header record, Table Record, column descriptor record of each column in the table, and one or more data records of each row in the table. A pc/IXF file record consists of fields that contain character data.

Part 1: Data Export (Export)
Example 1: export all data in the Org table to the file C: \ ORG. TXT.
Export to c: \ org.txt of del select * from org

Here, of del indicates the type of the exported file. In this example, it is exported to a non-bounded text file. The select * from org following is an SQL statement, the result of this statement is the data to be exported.

Example 2: Change the control operator of the del Format File
Export to c: \ staff.txt of del modified by coldel $ chardel ''decplusblank select * from staff
In this example, the modified clause is used to control various symbols. coldel indicates the delimiter between fields. By default, it is a comma. Now it is changed to $. chardel indicates the symbol used to reference string fields, by default, it is enclosed by a pair of double quotes. Now it is enclosed by a pair of single quotes. decplusblank indicates that the front plus sign is replaced by space for the decimal data type, by default, digits plus and minus signs are added before the decimal data.

Example 3: export data to a file in ASC format
The Export command does not support files in ASC format. to Export such a regular format as ASC, the programmer needs to convert all data types into fixed-length strings, then combine the fields to be exported into one field.
For example, create table n with the following structure:
Create table n (a int, B date, c time, d varchar (5), e char (4), f double)
Insert two pieces of data:
Insert into n values (15, '1970-10-21 ', '23: 12: 23', 'abc', 'hh', 2004)
Insert into n values (5, '2017-1-21 ', '3: 12: 23', 'bc', 'hhh', 2004)
To export the two data to a file in a regular format, perform the following operations:
Export to c: \ test.txt of d

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.