1
A
回答
0
使用Unix/Windows上的Db2,可以使用IMPORT命令或LOAD命令。另外INGEST命令還可以使用其他方法。
使用IMPORT或LOAD,有兩種方法可以使用「METHOD P」或在INSERT子句中指定目標列的順序。下面有兩個示例。
第一個例子使用「方法P」爲導入:
有三個CSV文件,它們的三列是按照不同的順序,並用三列的目標表(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.
第二個示例使用插入的有序列目標來匹配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.
相關問題
- 1. 結合幾行的CSV文件導入基於一定條件
- 2. 如何將多個csv文件合併爲一個CSV文件
- 3. 如何使用.NET將CSV文件導入DB2數據庫?
- 4. 如何導入csv文件
- 5. 合併幾個pdf文件
- 6. 如何合併幾百列在CSV與Python文件
- 7. 合併兩個csv文件
- 8. 合併多個CSV文件
- 9. 合併2個csv文件
- 10. 合併兩個CSV文件
- 11. 合併多個CSV文件
- 12. 合併多個csv文件
- 13. 合併幾個csv文件並將文件名存儲爲變量 - Python
- 14. 如何將多個csv文件合併爲1個SAS文件
- 15. 導入* .csv併合並工作表
- 16. 導入幾個csv文件並使用熊貓在Python中連接
- 17. 在幾個文本文件合併列
- 18. 合併多個的.csv文件合併成一個
- 19. 如何使用PHP將3個CSV文件合併爲1個CSV文件?
- 20. 從csv導入幾行R
- 21. PHP寫入csv文件合併標頭
- 22. 導入CSV文件
- 23. 導入CSV文件
- 24. 如何合併兩個文本文件,並轉換成csv文件斯卡拉
- 25. 從db2表中的csv文件導入數據
- 26. 導入CSV文件,並使用VB2008
- 27. 寫入CSV文件並將其導出?
- 28. Python - 合併從csv文件導入的Dask數據框
- 29. 合併幾個事件
- 30. 導入幾個文本文件到R
是Unix/Linux上運行的Windows的DB2服務器? – mao