Solved

How to load a pipe delimited text file to a database table in DB2

Posted on 2010-11-12
10
4,108 Views
Last Modified: 2012-05-10
Hi,

I want to load a text file to a database table in DB2. If it is a comma delimited file, it is loading perfectly, but if it is pipe delimited, it is failing. Why is that? I want to be able to keep the option of using both pipe or comma delimited files. here is the command I am using for comma delimited which is working fine--

module load ibmdb2/client/8.2.7
db3 connect to DataBase_Server
db2 load client from '~/file/myinfo.txt' of del MODIFIED BY COLDEL,INSERT INTO myinfo check pending cascade immediate

But if I use pipe, it is failing.

module load ibmdb2/client/8.2.7
db3 connect to DataBase_Server
db2 load client from '~/file/myinfo.txt' of del MODIFIED BY COLDEL|INSERT INTO myinfo check pending cascade immediate

Can I have the option of specifying the syntax in such a way, that it is either a pipe or a comma delimited file?
0
Comment
Question by:sunny82
  • 5
  • 3
  • 2
10 Comments
 
LVL 45

Expert Comment

by:Kdo
ID: 34121286
Hi Sunny,

DB2 has no issue with your using a pipe symbol as the field delimiter.  My guess is that the underlying operating system is attempting to handle the pipe symbol so that DB2 never sees it.

If you'll escape the symbol, you should be fine.

What's the underlying operating system?



Kent
0
 
LVL 37

Expert Comment

by:momi_sabag
ID: 34121296
the answer is no
you can't have mixed delimiters in your file
it is either comma or pipe (or any other character...) but it has to be consistent
0
 
LVL 45

Expert Comment

by:Kdo
ID: 34121323
You can also quote the delimiter character, depending on the O/S.

  LOAD .. MODIFIED BY COLDEL'|'

or

  LOAD .. MODIFIED BY COLDEL "|"


Kent
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

Author Comment

by:sunny82
ID: 34121457
If I use LOAD .. MODIFIED BY COLDEL'|'

I am getting the following
SQL0104N  An unexpected token "END-OF-STATEMENT" was found following
"IMMEDIATE".  Expected tokens may include:  "REMOTE".  SQLSTATE=42601

If I use  LOAD .. MODIFIED BY COLDEL "|"
same error as above

If I use LOAD .. MODIFIED BY COLDEL \|
same error as above

If I use LOAD .. MODIFIED BY COLDEL|
-ksh: INSERT: not found [No such file or directory]

On the other hand,
LOAD .. MODIFIED BY COLDEL,
is working perfectly

The underlying OS is Unix

0
 

Author Comment

by:sunny82
ID: 34121550
Any ideas why this peculiar behavior is happening and how to solve it.
0
 
LVL 45

Expert Comment

by:Kdo
ID: 34121554
If I use  LOAD .. MODIFIED BY COLDEL "|"
same error as above


Take out the space between COLDEL and "|"



0
 

Author Comment

by:sunny82
ID: 34121724
This is what I ran, there is no space between COLDEL and "|"

db2 load client from '~/file/myinfo.txt' of del MODIFIED BY COLDEL"|"INSERT INTO myinfo check pending cascade immediate

giving me the error

SQL0104N  An unexpected token "END-OF-STATEMENT" was found following
"IMMEDIATE".  Expected tokens may include:  "REMOTE".  SQLSTATE=42601
0
 

Author Comment

by:sunny82
ID: 34121811
On the other hand, if I do this --

db2 load client from '~/file/myinfo.txt' of del MODIFIED BY COLDEL,INSERT INTO myinfo check pending cascade immediate

It works just fine

0
 
LVL 37

Accepted Solution

by:
momi_sabag earned 500 total points
ID: 34121818
the easiest solution will probably be to write the hex representation of |

from information center:
The character must be specified in the code page of the source data.
The character code point (instead of the character symbol), can be specified using the syntax xJJ or 0xJJ, where JJ is the hexadecimal representation of the code point. For example, to specify the # character as a column delimiter, use one of the following:
    ... modified by coldel# ...
   ... modified by coldel0x23 ...
   ... modified by coldelX23 ...

0
 

Author Comment

by:sunny82
ID: 34124289
The Hex solution worked finally !!! Many thanks..

0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ORA-12560: TNS:protocol adapter error 8 130
Fixing Non-Standard characters in text 8 103
Unrecognized Database Format 8 107
SQL Query 34 99
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Creating and Managing Databases with phpMyAdmin in cPanel.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question