I have been trying to export a table from db2 from one external source to another, so far, I noticed that there is an error while I tried to import it on the source table.
I was using this on a shell script:
myDate=$(date +"%Y%m%d%I%M")
myPath=/tmp/test
myDataSource="external"
myTableName=tableSchema.sourceTable
db2 +w -vm "export to $myPath/$myDataSource.$myTableName.$myDate.ixf of ixf
messages $myPath/$myDataSource.$myTableName.$myDate.ixf.xmsg
SELECT * from $myTableName"
After further investigation, it seemed like there was a weird character "▒" being inserted. I checked the source and there wasn't any weird character. SO the after checking on detail I issued this command:
select *
from SYSIBM.SYSCOLUMNS
where
tbcreator = 'SOURCESCHEMA'
and tbname = 'SOURCETABLE'
for fetch only with ur;
Which showed that the CCSID on the source columns is 37. I did the same on the target schema and the CCSID for the columns is 1208.
When I tried to export the table again forcing it to convert to CCSID 1208 adding modified by codepage=1208:
db2 +w -vm "export to $myPath/$myDataSource.$myTableName.$myDate.ixf of ixf
modified by codepage=1208
messages $myPath/$myDataSource.$myTableName.$myDate.ixf.xmsg
SELECT * from $myTableName"
This causes the script to work, but I get this warning:
SQL3132W The character data in column "COLUMN" will be truncated to size "4".
Said column is the same size on the source and the target but it seems that due to the CCSID I will need to change the size on the target (I can't change anything on the source and changing the CCSID on the target will break things on the target) So, my questions are:
- How do I calculate the size needed for each varchar/char column depending on the encoding, for example if a varchar(4) on CCSID 37 will need a varchar(5) to hold a value with CCSID 1208?
Will it be possible to do something like:
SELECT CAST(COLUMN as VARCHAR(12) CCSID 1208) --and for all columns from tableSchema.sourceTable;
So I don't lose any part of those strings.
- What about the numbers?
Thanks!