The task is fairly simply --- I need to load the content of some text files into DB2. There are many ways to do so, but since I only need to this only once (hopefully), I want to find an easy way without writing any external code.

So here is the solution:

(1) create a table containing a CLOB (VARCHAR should work as well, if we know the maxium size of the files in advance) column. For example:


(2) put the files to be loaded into one directory and create a .del file based on their names. The content in the .del file should based on the table you have just created. For instance, a .del file for the example table created in (1) should look like the following:


2, "doc2, txt"


where the first value is the id, and the second value is the name of a file to be loaded.

(3) load the content

import from test.del of del lobs from /home/dirName/ modified by lobsinfile replace into test

Depends on the exact nature of your task, you may add additional modifiers to the import command. But the above three steps should be adequate in many cases.

Finally, just to make sure that the files are properly loaded into the database, we can export part of the table and view the content:

export to myfile.del of del lobs to outDirName lobfile lobs1, lobs2 modified by lobsinfile select * from test where docid < 10


comments powered by Disqus