Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Blank spaces at the end of each record 2

Status
Not open for further replies.

pnad

Technical User
May 2, 2006
133
US
Hello all,

I have written the following code to generate a fixed length flat file but it puts spaces at the end of each record that is outputted onto the flat file:

SET FEEDBACK off
SET HEADING off
SET PAGESIZE 0
SET LINESIZE 200
SET TERM off
SET VERIFY off

SPOOL C:\ohco\filessenttorust\PolicyInfo.txt

select rpad(companycode||''||policynumber||''||secondarycompanycode, 12)||
rpad(to_char(futureadjustmentamount,'999.99'),7)||
rpad(to_char(datefutureadjustmentmade,'yyyymmdd'),8)||
rpad(to_char(trunc(sysdate),'yyyymmdd'),8)
from ohco.policyrecord
where datefutureadjustmentmade is not null
and futureadjustmentamount is not null
and datefutureadjustmentmade between trunc(next_day(sysdate-7,'SATURDAY')) and trunc(sysdate);



SPOOL off

SET PAGESIZE 14
SET TERM on
SET VERIFY on
SET FEEDBACK on
SET HEADING on

exit

How do I get rid of the spaces at the end of each record on the file.

Any help will be appreciated.

Thanks.
 
Setting the linesize to 35 fixed the problem.

Thanks.
 

Instead of 'concatinating' columns and using the RPAD()/LPAD() functions, you should consider using the following:

SET COLSEP '' <= to set columnseparator to null
COL <col1> FOR A<nn> <= to set the char column width
COL <col2> FOR 9999... <= to set numeric columns

For dates you are stuck with TO_CHAR() function.

[3eyes]

----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
PNAD,

There is a better method (for at least two reasons) to get rid of trailing spaces at the end of each row:

1) You don't have to manually "count" how many characters of output you have per row
2) If the rows of of unequal length, this method trims off the trailing blanks (even if a row is less than 35 characters as in your case):
Code:
set trimspool on
Let us know how this works for you.

[santa]Mufasa
(aka Dave of Sandy, Utah, USA)
[I can provide you with low-cost, remote Database Administration services: see our website and contact me via www.dasages.com]
 

Yes trimspool is better. Should be combined also with a 'comma separated' fields (CSV) file.

But in order to generate records of a given fixed length, you need to set the linesize and each column length, and not use trimspool.

Now, for fixed-length records, remember the 'spool' command will add a 'line-feed' character (CHR(10)) at the end of each record.

[noevil]

----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
LKBrwnDBA said:
for fixed-length records, remember the 'spool' command will add a 'line-feed' character (CHR(10)) at the end of each record.
Oracle adds a CHR(10) to the end of each row of output, whether fixed-length or variable-length .csv, right LK?

[santa]Mufasa
(aka Dave of Sandy, Utah, USA)
[I can provide you with low-cost, remote Database Administration services: see our website and contact me via www.dasages.com]
 

Right. [peace]


----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 


PS: I was just trying to remind him of that fact --


----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
Thank you all for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top