Home » SQL & PL/SQL » SQL & PL/SQL » handling leading zeros in a csv file
handling leading zeros in a csv file [message #303207] Thu, 28 February 2008 06:57 Go to next message
trichyselva
Messages: 6
Registered: February 2006
Location: chennai
Junior Member
i have a requirement in that i have to create a csv file with entries like this

0002 4543
0234 3862
9876 3333

i am using utl_file option for this

the first column is id when i try to write in to a csv file with left padding of 0 even then it is displaying as

2 4543
234 3862
9876 3333

when the id's are 2 ,234, 9876 etc.

but i want the 0's to be there in the first column like the one mentioned above

how to solve it

thanks in advance

this is the line using this i am writing into a csv file

index_record := LPAD(valind(indx).index_code,4,'0') ||','||valind(indx).index_count;
UTL_FILE.PUT_LINE(indexHandle,index_record);



suggestions welcome
Re: handling leading zeros in a csv file [message #303211 is a reply to message #303207] Thu, 28 February 2008 07:17 Go to previous messageGo to next message
Frank
Messages: 7880
Registered: March 2000
Senior Member
Did you read this?

Moved to newbie-forum.
Re: handling leading zeros in a csv file [message #303212 is a reply to message #303207] Thu, 28 February 2008 07:26 Go to previous messageGo to next message
Frank
Messages: 7880
Registered: March 2000
Senior Member
Hint: look at the format models available. You have to convert your variable to a character.
Re: handling leading zeros in a csv file [message #303419 is a reply to message #303212] Fri, 29 February 2008 05:31 Go to previous messageGo to next message
trichyselva
Messages: 6
Registered: February 2006
Location: chennai
Junior Member
it's not working i tried
index_record := to_char(LPAD(valind(indx).index_code,4,'0'),'0000') ||','||valind(indx).index_count;
UTL_FILE.PUT_LINE(indexHandle,index_record);

but even then it is truncating the leading zeros

Suggestions welcome
Re: handling leading zeros in a csv file [message #303422 is a reply to message #303419] Fri, 29 February 2008 05:59 Go to previous message
Michel Cadot
Messages: 64139
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Forget your LPAD.
Use TO_CHAR for both values.
Copy and paste the execution.

Regards
Michel

[Updated on: Fri, 29 February 2008 05:59]

Report message to a moderator

Previous Topic: Comments for external tables
Next Topic: SEQUENCEs continuous
Goto Forum:
  


Current Time: Thu Dec 08 08:09:18 CST 2016

Total time taken to generate the page: 0.09485 seconds