Page 1 of 1

APT_ORACLE_PRESERVE_BLANKS

Posted: Thu Jul 19, 2012 12:18 am
by SachinCho
Hi,
We are trying to load flat file on unix server to oracle table through oracle enterprise stage. I have a input column customer_name which contains some trailing spaces which we need to preserve while loading. e.g "sachin " should be loaded as it is and not as "sachin". For this purpose we have set environment variable APT_ORACLE_PRESERVE_BLANKS to true. But after doing this data loaded in traget table is like "sachin " as my customer_name field is of varchar(20). It is adding extra spaces treating like char field.
Oracle version used is 10g
Any pointers to this issue. Saw one post to similar to ine but there were no answers provided

Posted: Thu Jul 19, 2012 2:29 am
by ray.wurlod
You asked it to preserve blanks and it did so. What's the problem?

Posted: Thu Jul 19, 2012 2:35 am
by SachinCho
Hi Ray,
but it shud preserve only existing spaces right. And should not pad string with additional spaces based on length of the string.

Posted: Thu Jul 19, 2012 3:04 am
by SachinCho
small correction

it is adding extra spaces in loaded string. If my column has length as varchar(20) then loaded string would be "sachin " + 13 spaces

In earlier post this was not reflecting properly hence confusion

Posted: Thu Jul 19, 2012 5:59 am
by ray.wurlod
Are you sure it's a VARCHAR not a CHAR in the database? If it were CHAR then the database itself might pad with space characters.

Posted: Thu Jul 19, 2012 6:37 am
by chulett
Are you perhaps reading it from your source as a CHAR? You are correct that it should only preserve any existing trailing spaces and not add anything to the data when it is sent to Oracle.

Posted: Thu Jul 19, 2012 10:57 pm
by SachinCho
Pretty sure that database has datatype as varchar2(20) and also while reading from seq file I am reading as varchar. Only thing is not specified any length while reading from file

Posted: Thu Jul 19, 2012 11:53 pm
by Kryt0n
Are you bulk loading or inserting?

Push your data to a sequential file instead of your oracle stage so you can see if any modification has happened prior to oracle

Posted: Fri Jul 20, 2012 12:40 am
by SachinCho
Yes. Already done this. Have added peek parallel to oracle stage and data is coming properly till peek stage. Only existing spaces in string are getting preserved. But in ORACLE it is padded with additional spaces based on length of the string

Posted: Fri Jul 20, 2012 2:18 am
by ArndW
I think Kryt0n might have the correct idea - what method are you using to load into Oracle - if using BULK it might be using a fixed-width file which in turn might be causing the inserting of extra spaces.

Posted: Fri Jul 20, 2012 2:35 am
by SachinCho
I am using write method as Load. I tried reading generated ctl file for the same and following are contents of the same. It is using some "FIX 20".

OPTIONS(DIRECT=TRUE, PARALLEL=TRUE, SKIP_INDEX_MAINTENANCE=YES)

LOAD DATA INFILE '/data03/Scratch/Scratch12/ora.1183988.635332.fifo.0.out' "FIX 20"
APPEND PRESERVE BLANKS INTO TABLE Name_test
(
NAME POSITION(1:20) NULLIF (1:20) = BLANKS

)
so I think Kryt0n has given hint in correct direction. but how to override this while using load method

Posted: Fri Jul 20, 2012 3:35 am
by ArndW
I think that using this method you don't have a choice, the file is created using fixed widths (which can be parallelized easily, unlike variable width files) so preserving the original number of trailing spaces won't be possible. Is using the normal insert method an option?

Re: APT_ORACLE_PRESERVE_BLANKS

Posted: Sat Sep 29, 2012 12:12 pm
by paultechm
Recently I have had the same issue ie after adding APT_ORACLE_PRESERVE_BLANKS all the character columns have been padded with space. I have found a workaround for this, just updating the old thread which may help others.

Workaround

Removed length values in the metadata for all the columns in the load oracle stage .The out put has come as expected, even source column value with space also loaded correctly.

-Paul J