Problem Note 41451: Trailing blanks appear at the end of a variable when you bulk load data to Oracle
SAS/ACCESS® Interface to Oracle adds trailing blanks at the end of a variable when you bulk load data to the Oracle database. The SAS® System handles reading variables of type VARCHAR this way because SAS does not have a variable-length data type. Therefore, variable values that are less than the full length of the variable are padded with blanks. For example, suppose a variable is defined with a length of 10 and you store the value ABC in the variable. What the software actually stores is the value ABC followed by seven blanks.
To remove the trailing blanks at the end of a variable, use any of the following options:
- Use the SAS TRIMN() function after data is loaded. The TRIMN() function is passed to the Oracle database as the RTRIM() function. This conversion removes trailing blanks, but it does require additional coding and an extra step.
- Do not use bulk loading. If you use the BULKLOAD=NO option, then no trailing blanks occur.
- Strip the blanks by either modifying or changing the control file that is created by SAS for use by the Oracle SQL*Loader.
Example of a Control File
OPTIONS (DIRECT=TRUE , ERRORS=1000000)
LOAD DATA INFILE "amy_bulk.dat" "FIX 38"
INTO TABLE AMY_BULK APPEND (
"ID" POSITION(1:8) DOUBLE NULLIF "ID"=BLANKS ,
"INFO" POSITION(9:38) CHAR "decode(:info,null,' ')"
)
Table definition:
Name Null? Type
----------------------------------------- -------- --------------
ID NUMBER
INFO NOT NULL VARCHAR2(30)
Code examples that illustrate how to avoid the trailing blanks:
- In this example, the NOT NULL columns use the database default values.
/* Sample_20100816_1: Oracle bulk loading, without trailing blanks, into NOT NULL columns. */
/* Use BULKLOAD=YES and DROP=INFO to remove columns so that the columns use database default values. */
/* Variables need to be modified. */
%let myuser=user-id;
%let mypass=password;
%let mypath=path-name;
/* End of modified variables. */
/* Generic code. */
data test;
id=1; info=''; output;
id=2; info=' '; output;
run;
libname x oracle user=&myuser pass=&mypass path=&mypath;
proc append base=x.amy_bulk(bulkload=yes bl_direct_path=no drop=info)
data=test(drop=info);
run;
/* End of sample_20100816_1. */
- This example loads the data and then reloads the rejected rows (assuming that there are not too many rejected rows because of NOT NULL column issues).
/* Sample_20100816_2: Oracle bulk loading, without trailing blanks, into NOT NULL columns. */
/* Use BULKLOAD=YES and reload the rejected rows. */
/* Variables need to be modified. */
%let myuser=user-id;
%let mypass=password;
%let mypath=path-name;
/* End of modified variables. */
/* Generic code */
data test;
length info $30.;
id=21; info='good data'; output;
id=22; info=''; output;
id=23; info=' '; output;
run;
libname x oracle user=&myuser pass=&mypass path=&mypath;
/* You might need to adject the file path depending on the platform used */
proc append base=x.amy_bulk(bulkload=yes bl_datafile="c:/temp/amy_bulk.dat" bl_delete_datafile=no)
data=test;
run;
/* End of sample_20100816_2*/
To load the rejected rows:
- Open a command window, and submit the command cd c:\temp.
- Locate the bad file and the control file.
- Move the bad file to a data file using, for example, the command mv BL_AMY_BULK_6.bad BL_AMY_BULK_6.dat.
- Modify the control file. (See Example of Control File for the original control file that is modified in this step). Add the following information to the NOT NULL columns in the new control file, as follows:
OPTIONS (DIRECT=TRUE , ERRORS=1000000) LOAD DATA INFILE "c:/temp/amy_bulk.dat" "FIX 38"
INTO TABLE AMY_BULK APPEND ("ID" POSITION(1:8) DOUBLE NULLIF "ID"=BLANKS
"INFO" POSITION(9:38) CHAR "decode(:info, null, ' ')")
- Run the SQL&Loader utility, as follows:
sqlldr userid=user-id/password control=BL_AMY_BULK_6.ctl
- Check the log file to ensure that all of the data is loaded.
Note: In case A, the KEEP= and DROP= data set options work for the APPEND procedure, with the insertion of limited columns inserted. However, the following warning is issued in the log, regardless, if you use the system options DKROCOND=NOWARN and DKRICOND=NOWARN along with the FORCE NOWARN procedure option.
'WARNING: The DROP, KEEP AND RENAME options are ignored for the BASE data set.'
Operating System and Release Information
SAS System | SAS/ACCESS Interface to Oracle | Microsoft® Windows® for 64-Bit Itanium-based Systems | 9.1 TS1M3 SP4 | |
Microsoft Windows Server 2003 Datacenter 64-bit Edition | 9.1 TS1M3 SP4 | |
Microsoft Windows Server 2003 Enterprise 64-bit Edition | 9.1 TS1M3 SP4 | |
Microsoft Windows XP 64-bit Edition | 9.1 TS1M3 SP4 | |
Microsoft Windows 2000 Advanced Server | 9.1 TS1M3 SP4 | |
Microsoft Windows 2000 Datacenter Server | 9.1 TS1M3 SP4 | |
Microsoft Windows 2000 Server | 9.1 TS1M3 SP4 | |
Microsoft Windows 2000 Professional | 9.1 TS1M3 SP4 | |
Microsoft Windows NT Workstation | 9.1 TS1M3 SP4 | |
Microsoft Windows Server 2003 Datacenter Edition | 9.1 TS1M3 SP4 | |
Microsoft Windows Server 2003 Enterprise Edition | 9.1 TS1M3 SP4 | |
Microsoft Windows Server 2003 Standard Edition | 9.1 TS1M3 SP4 | |
Microsoft Windows XP Professional | 9.1 TS1M3 SP4 | |
Windows Vista | 9.1 TS1M3 SP4 | |
Windows Vista for x64 | 9.1 TS1M3 SP4 | |
64-bit Enabled AIX | 9.1 TS1M3 SP4 | |
64-bit Enabled HP-UX | 9.1 TS1M3 SP4 | |
64-bit Enabled Solaris | 9.1 TS1M3 SP4 | |
HP-UX IPF | 9.1 TS1M3 SP4 | |
Linux | 9.1 TS1M3 SP4 | |
Linux on Itanium | 9.1 TS1M3 SP4 | |
OpenVMS Alpha | 9.1 TS1M3 SP4 | |
Solaris for x64 | 9.1 TS1M3 SP4 | |
Tru64 UNIX | 9.1 TS1M3 SP4 | |
Microsoft® Windows® for x64 | 9.2 TS2M3 | |
Microsoft Windows Server 2003 for x64 | 9.2 TS2M3 | |
Microsoft Windows Server 2008 | 9.2 TS2M3 | |
Microsoft Windows Server 2008 for x64 | 9.2 TS2M3 | |
Windows 7 Enterprise 32 bit | 9.2 TS2M3 | |
Windows 7 Enterprise x64 | 9.2 TS2M3 | |
Windows 7 Home Premium 32 bit | 9.2 TS2M3 | |
Windows 7 Home Premium x64 | 9.2 TS2M3 | |
Windows 7 Professional 32 bit | 9.2 TS2M3 | |
Windows 7 Professional x64 | 9.2 TS2M3 | |
Windows 7 Ultimate 32 bit | 9.2 TS2M3 | |
Windows 7 Ultimate x64 | 9.2 TS2M3 | |
Linux for x64 | 9.2 TS2M3 | |
OpenVMS on HP Integrity | 9.2 TS2M3 | |
*
For software releases that are not yet generally available, the Fixed
Release is the software release in which the problem is planned to be
fixed.