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!

Preserving "Leading Zeroes" when downloading a CSV File

Roxy rollersJun 3 2021 — edited Jun 3 2021

I have stumbled upon an issue which was working just fine in the past. I have an Interactive Report (Oracle APEX) where I have the option of downloading it as a CSV. I do have a STUDENT_ID field where it varchar2(4) in the database and I have my ID's saved as "0001", "0002", "1067" etc. As we all know, to preserve the leading zeroes when downloading as a CSV has it's challenges. So, in the past, I was having to do this:

select '="' || student_id || '"' from student_tb

This worked out well in the past. However, I am now noticing (Higher version of Oracle) that an annoying tab space is being injected in the beginning. When I open the CSV in notepad, I noticed that it was in the following fashion:
Exhibit #1

"	=""0002"""

So, when you open the Excel file, it looks like this:
image.pngand in the past it was as follows:
Exhibit #2

"=""0002"""

When you open the Excel File, it should look like this:
image.png
If I go and remove the tab space from Exhibit #1 and then open it in CSV, the problem gets rectified. Any idea if there is another way in SQL to format this so I preserve the leading zeroes and have it open correctly in Excel? I tried doing TRIM but that did not help either.
Thanks in advance

Comments

Post Details

Added on Jun 3 2021
2 comments
2,140 views