IMPORT script on IBM DB2 Cloud using RUN SQL Interface

浪子不回头ぞ 提交于 2019-12-11 15:44:08

问题


I am trying to import a JOBFILE.CSV from my hard drive into the table JOB using the RUN SQL script in IBM DB2 cloud.

CALL SYSPROC.ADMIN_CMD('IMPORT FROM "C:/DATAFILE/JOBFILE.CSV" 
OF DEL INSERT INTO JOB');

I am getting this error:

An I/O error (reason = "sqlofopn -2029060079") occurred while opening the input file.. SQLCODE=-3030, SQLSTATE= , DRIVER=4.25.1301

It seems the path that I have set is not working. As I have researched JOBFILE.CSV must be loaded first into the DB2 server before the IMPORT script could run.


回答1:


With a file located on a local client there are two options "basic" options (excluding e.g. Db2 Cloud REST API to import the data)

  1. LOAD with a CLIENT keyword (work also for all Db2 LUW on-premise releases)
  2. Insert from an EXTERNAL TABLE (available in Db2 Cloud, Warehouse and 11.5 release)

The latter is typically the fastest. See an example with an input like this:

db2 "create table import_test(c1 int, c2 varchar(10))"
echo "1,'test1'" > data.del
echo "2,'test2'" >> data.del

To insert the data from the client we need we can run:

db2 "INSERT INTO import_test SELECT * FROM EXTERNAL '/home/db2v111/data.del' USING (DELIMITER ',' REMOTESOURCE YES)"
DB20000I  The SQL command completed successfully.

db2 "select * from import_test"

C1          C2        
----------- ----------
          2 'test2'   
          1 'test1'   

  2 record(s) selected.

More examples including importing data from S3 can be found in Loading data to IBM Cloud chapter of the documentation.



来源:https://stackoverflow.com/questions/57684865/import-script-on-ibm-db2-cloud-using-run-sql-interface

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!