2017-10-18 30 views
1

同じ列を持つ複数のCSVファイルがありますが、列の順序は異なります。DB2インポート - 複数のCSVファイルをマージする方法

これらのすべてのCSVファイルを「インポート」によってマージしたいと思います。

このインポートステートメントでお手伝いできますか?このインポートステートメントを列の順序と一致させるにはどうすればよいですか?

+0

あなたのDb2サーバはUnix/LinuxのWindowsで動作していますか? – mao

答えて

0

Unix/Windows上でDb2を使用すると、IMPORTコマンドまたはLOADコマンドを使用できます。さらに、INGESTコマンドで他の方法も可能です。

IMPORTまたはLOADの場合、「METHOD P」を使用するか、またはINSERT句のターゲット列の順序を指定する2つの方法があります。以下に2つの例を示します。

最初の例では、インポートするための「方法P」を使用:

3つのを持つ3つの列は異なる順序であるCSVファイル、3列(A、B、C)とターゲット表があります

create table mytab(a integer not null, b integer not null, c integer not null) 
DB20000I The SQL command completed successfully. 

!cat 1a.csv 
1,2,3 

!cat 1b.csv 
99,98,97 

!cat 1c.csv 
55,51,59 

import from 1a.csv of del method p(1,2,3) insert into mytab 
SQL3109N The utility is beginning to load data from file "1a.csv". 

SQL3110N The utility has completed processing. "1" rows were read from the 
input file. 

SQL3221W ...Begin COMMIT WORK. Input Record Count = "1". 

SQL3222W ...COMMIT of any database changes was successful. 

SQL3149N "1" rows were processed from the input file. "1" rows were 
successfully inserted into the table. "0" rows were rejected. 


Number of rows read   = 1 
Number of rows skipped  = 0 
Number of rows inserted  = 1 
Number of rows updated  = 0 
Number of rows rejected  = 0 
Number of rows committed = 1 


import from 1b.csv of del method p(3,2,1) insert into mytab 
SQL3109N The utility is beginning to load data from file "1b.csv". 

SQL3110N The utility has completed processing. "1" rows were read from the 
input file. 

SQL3221W ...Begin COMMIT WORK. Input Record Count = "1". 

SQL3222W ...COMMIT of any database changes was successful. 

SQL3149N "1" rows were processed from the input file. "1" rows were 
successfully inserted into the table. "0" rows were rejected. 


Number of rows read   = 1 
Number of rows skipped  = 0 
Number of rows inserted  = 1 
Number of rows updated  = 0 
Number of rows rejected  = 0 
Number of rows committed = 1 


import from 1c.csv of del method p(2,1,3) insert into mytab 
SQL3109N The utility is beginning to load data from file "1c.csv". 

SQL3110N The utility has completed processing. "1" rows were read from the 
input file. 

SQL3221W ...Begin COMMIT WORK. Input Record Count = "1". 

SQL3222W ...COMMIT of any database changes was successful. 

SQL3149N "1" rows were processed from the input file. "1" rows were 
successfully inserted into the table. "0" rows were rejected. 


Number of rows read   = 1 
Number of rows skipped  = 0 
Number of rows inserted  = 1 
Number of rows updated  = 0 
Number of rows rejected  = 0 
Number of rows committed = 1 


select * from mytab 

A   B   C   
----------- ----------- ----------- 
      1   2   3 
     97   98   99 
     51   55   59 

    3 record(s) selected. 

2番目の例では、CSVファイルの列ターゲットの順序と一致するように、挿入の順序付き列のターゲットを使用しています。

create table mynewtab(a integer not null, b integer not null, c integer not null) 
DB20000I The SQL command completed successfully. 

!cat 1a.csv 
1,2,3 

!cat 1b.csv 
99,98,97 

!cat 1c.csv 
55,51,59 

import from 1a.csv of del insert into mynewtab(a,b,c) 
SQL3109N The utility is beginning to load data from file "1a.csv". 

SQL3110N The utility has completed processing. "1" rows were read from the 
input file. 

SQL3221W ...Begin COMMIT WORK. Input Record Count = "1". 

SQL3222W ...COMMIT of any database changes was successful. 

SQL3149N "1" rows were processed from the input file. "1" rows were 
successfully inserted into the table. "0" rows were rejected. 


Number of rows read   = 1 
Number of rows skipped  = 0 
Number of rows inserted  = 1 
Number of rows updated  = 0 
Number of rows rejected  = 0 
Number of rows committed = 1 


import from 1b.csv of del insert into mynewtab(c,b,a) 
SQL3109N The utility is beginning to load data from file "1b.csv". 

SQL3110N The utility has completed processing. "1" rows were read from the 
input file. 

SQL3221W ...Begin COMMIT WORK. Input Record Count = "1". 

SQL3222W ...COMMIT of any database changes was successful. 

SQL3149N "1" rows were processed from the input file. "1" rows were 
successfully inserted into the table. "0" rows were rejected. 


Number of rows read   = 1 
Number of rows skipped  = 0 
Number of rows inserted  = 1 
Number of rows updated  = 0 
Number of rows rejected  = 0 
Number of rows committed = 1 


import from 1c.csv of del insert into mynewtab(b,a,c) 
SQL3109N The utility is beginning to load data from file "1c.csv". 

SQL3110N The utility has completed processing. "1" rows were read from the 
input file. 

SQL3221W ...Begin COMMIT WORK. Input Record Count = "1". 

SQL3222W ...COMMIT of any database changes was successful. 

SQL3149N "1" rows were processed from the input file. "1" rows were 
successfully inserted into the table. "0" rows were rejected. 


Number of rows read   = 1 
Number of rows skipped  = 0 
Number of rows inserted  = 1 
Number of rows updated  = 0 
Number of rows rejected  = 0 
Number of rows committed = 1 


select * from mynewtab 

A   B   C   
----------- ----------- ----------- 
      1   2   3 
     97   98   99 
     51   55   59 

    3 record(s) selected. 
関連する問題