Solved

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

Posted on 2010-11-12
10
4,334 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 2
10 Comments
 
LVL 45

Expert Comment

by:Kent Olsen
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:Kent Olsen
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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 

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:Kent Olsen
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

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

Suggested Solutions

Creating and Managing Databases with phpMyAdmin in cPanel.
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
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…

749 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