Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Outputing a fixed length string

346658Nov 12 2007 — edited Nov 12 2007
I'm trying to output a flat fixed length text file from a database table.
I'm using a cursor and a variable with %ROWTYPE for the data and "text_io.put_line" to output the data from variable "my_rec varchar(80);".

EXAMPLE:

CURSOR PTD_HEADER_cur IS
SELECT * FROM PTD_LIB.PTD_HEADER P
WHERE P.EIACODXA = :global.curr_proj_id and P.PCCNUMXC = :CONTROL.C_PCCNUMXC;

V_HDR PTD_LIB.PTD_HEADER%ROWTYPE;


The database table has many fields, all type of varchar2.

fld1 length 6
fld2 length 10
fld3 length 15
.
.
.
fldx

I retreive the data from the cursor sucessfully.

I want do do something like this to construct a output line:

my_rec := v_hdr.fld1 || v_hdr.fld2 || v_hdr.fld3;
text_io.put_line(LF$file,my_rec);


My problem is when one of the fields is null, for example fld2. I still need a 10 byte gap between fld1 and fld3 in my output text record
.
If the fld2 is not null, but is only 2 bytes in length, I still have to output those 2 bytes plus 8 spaces.
Any coding sugesstions??

Thanks Larry
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 10 2007
Added on Nov 12 2007
5 comments
1,791 views