If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > exporting into csv with condition

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-11-08, 10:20
ankur02018 ankur02018 is offline
Registered User
 
Join Date: Jun 2007
Posts: 189
Smile exporting into csv with condition

hi ,
I use to export table by following syntax

EXPORT TO C:\ESHOPBACKUP\ISMCND.csv OF DEL MODIFIED BY chardel"" coldel, decpt. datesiso decplusblank MESSAGES C:\ESHOPBACKUP\ISMCND.txt SELECT * FROM ISM.ISMCND;

for table ISMCND

When export in csv such that where is NULL in column there will be blank cell in output csv file

I want that in place of blank cell I want NULL charactor to be written there
Reply With Quote
  #2 (permalink)  
Old 07-11-08, 10:31
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
Please explain what you mean, maybe use some examples. Also explain why you want it that way. What DB2 version and OS?

Andy
Reply With Quote
  #3 (permalink)  
Old 07-14-08, 03:05
ankur02018 ankur02018 is offline
Registered User
 
Join Date: Jun 2007
Posts: 189
Smile

Quote:
Originally Posted by ARWinner
Please explain what you mean, maybe use some examples. Also explain why you want it that way. What DB2 version and OS?

Andy

OS:-Windows XP
database version:- DB2 7.1
table from that export :-ISMCND
export syntax:-EXPORT TO C:\ESHOPBACKUP\ISMCND.csv OF DEL MODIFIED BY chardel"" coldel, decpt. datesiso decplusblank MESSAGES C:\ESHOPBACKUP\ISMCND.txt SELECT * FROM ISM.ISMCND;

Purpose :after exporting this csv file i want to upload this csv into Mysql data table

Problem:-Now problem is that I got csv file from DB2 table such as where is NULL in DB2 there is BLANK CELL in csv file and when I load this file This blank cell inserts 0 instead of NULL

If in place of Blank cell of csv there will be NULL charactor then to load this file in MySQL will give null value instead of 0

This is the complete information:Please provide solution
Reply With Quote
  #4 (permalink)  
Old 07-14-08, 04:29
nick.ncs nick.ncs is offline
Registered User
 
Join Date: May 2007
Location: somewhere in dbforums
Posts: 221
well you can change your following statement
SELECT * FROM ISM.ISMCND

to something like this

SELECT
COLUMN1, ...... where i am assuming COLUMN1 is a primary key .....
CASE
WHEN COLUMN2 IS NULL ... where COLUMN2 can be nullable
THEN
'NULL'
ELSE
COLUMN2
END AS COLUMN2,
.... similarly for all other columns which can hold NULL values ....
FROM
ISM.ISMCND

this will basically print NULL wherever the columns hold NULL values
Reply With Quote
  #5 (permalink)  
Old 07-14-08, 06:43
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
This will only work for columns that have a string data type. For all other columns, you have to work-around this like here:
Code:
SELECT column1,
       COALESCE(string_col2, 'NULL'),
       COALESCE(CHAR(int_col3), 'NULL')
FROM ...
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #6 (permalink)  
Old 07-14-08, 06:54
nick.ncs nick.ncs is offline
Registered User
 
Join Date: May 2007
Location: somewhere in dbforums
Posts: 221
grrrr..... now I know why experience counts.... had faced this issue and forgotten all about it
Reply With Quote
  #7 (permalink)  
Old 07-14-08, 10:40
ankur02018 ankur02018 is offline
Registered User
 
Join Date: Jun 2007
Posts: 189
Smile

Quote:
Originally Posted by stolze
This will only work for columns that have a string data type. For all other columns, you have to work-around this like here:
Code:
SELECT column1,
       COALESCE(string_col2, 'NULL'),
       COALESCE(CHAR(int_col3), 'NULL')
FROM ...
Thanks for giving solution

here is following table ISMCND description
Column Type Type
name schema name
------------------------------ --------- -----------------
CNDRFNUM SYSIBM BIGINT
CNDGROUP SYSIBM VARCHAR
CNDCODE SYSIBM CHARACTER
CNDDESC SYSIBM VARCHAR
CNDCNDRFNUM SYSIBM BIGINT
CREATEDATE SYSIBM TIMESTAMP
MODIDATE SYSIBM TIMESTAMP
DELETED SYSIBM CHARACTER
CREATEDBY SYSIBM BIGINT


for this export syntax

EXPORT TO C:\ESHOPBACKUP\ISMCND.csv OF DEL MODIFIED BY chardel"" coldel, decpt. datesiso decplusblank MESSAGES C:\ESHOPBACKUP\ISMCND.txt select CNDRFNUM, CNDGROUP, CNDCODE, CNDDESC, CNDCNDRFNUM (BIGINT_COL5,'NULL'), CREATEDATE, MODIDATE, DELETED, CREATEDBY from ISMCND

showing error

SQL3022N An SQL error "-206" occurred while processing the SELECT string in the Action String parameter.

what could be the export syntax according you?
Reply With Quote
  #8 (permalink)  
Old 07-14-08, 11:30
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
What is this supposed to be:
Code:
CNDCNDRFNUM (BIGINT_COL5,'NULL')
COALESCE is a standard SQL function, which returns the first non-null value of its input arguments. So I guess you want to do that:
Code:
COALESCE(CHAR(CNDCNDRFNUM), 'NULL')
Btw: those are very cryptic table/column names and if you have the chance, I would suggest to rename them to something readable and comprehensible. The times where things had to be short due to some limitations are gone for more than 20 years already.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #9 (permalink)  
Old 07-15-08, 03:00
ankur02018 ankur02018 is offline
Registered User
 
Join Date: Jun 2007
Posts: 189
Smile

Quote:
Originally Posted by stolze
COALESCE is a standard SQL function, which returns the first non-null value of its input arguments. So I guess you want to do that:
Code:
COALESCE(CHAR(CNDCNDRFNUM), 'NULL')
Btw: those are very cryptic table/column names and if you have the chance, I would suggest to rename them to something readable and comprehensible. The times where things had to be short due to some limitations are gone for more than 20 years already.

Thanks for giving suggestion and solution

I am converting DB2 data to MySQL data
There are 178 Tables and some of them have 15 to 25 fields
so by using COALESCE It is too much hectic to put on every column

so How to put NULL charactor for all tables
Reply With Quote
  #10 (permalink)  
Old 07-15-08, 09:04
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
Let's take a step back: why do you want to have such a conversion in the first place? Does MySQL need it?
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #11 (permalink)  
Old 07-15-08, 09:43
ankur02018 ankur02018 is offline
Registered User
 
Join Date: Jun 2007
Posts: 189
Smile

Quote:
Originally Posted by stolze
Let's take a step back: why do you want to have such a conversion in the first place? Does MySQL need it?
I use following syntax to load csv file in mysql

LOAD DATA LOCAL INFILE 'ISMCND.csv' INTO TABLE test.ISMCND FIELDS TERMINATED BY ',' ENCLOSED BY '"' ESCAPED BY '\\';

It is required to put NULL charactor in place of blank cell because when I load that csv file , entry of Blank cell is 0 for the table in mysql but when we use NULL charactor there will be right entry mean null instead of 0

so how to convert this blank cell to NULL charactor for many table while checking each table for column is much much hactic
Reply With Quote
  #12 (permalink)  
Old 07-15-08, 10:42
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
I guess your best bet is to run a tool like SED or AWK over the DB2 output to convert the format to whatever makes MySQL happy.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #13 (permalink)  
Old 07-16-08, 04:02
ankur02018 ankur02018 is offline
Registered User
 
Join Date: Jun 2007
Posts: 189
Smile

Quote:
Originally Posted by stolze
I guess your best bet is to run a tool like SED or AWK over the DB2 output to convert the format to whatever makes MySQL happy.
Thanks Please provide me Link for SED or AWK tool for DB2
Reply With Quote
  #14 (permalink)  
Old 07-16-08, 07:34
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
sed and awk are regular Unix tools.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #15 (permalink)  
Old 07-16-08, 09:34
ankur02018 ankur02018 is offline
Registered User
 
Join Date: Jun 2007
Posts: 189
Smile

Quote:
Originally Posted by stolze
sed and awk are regular Unix tools.
Thanks of your support for giving me such information
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On