Skip to Main Content

APEX

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!

Parsing Data From CSV - Column Headers Show in 2nd Row

Tim Matthews-OracleNov 28 2019 — edited Nov 29 2019

Hey Everyone,

I'm trying to recreate the csv/file upload parser using the following walk through (https://blogs.oracle.com/apex/super-easy-csv-xlsx-json-or-xml-parsing-about-the-apex_data_parser-package). This example pretty much mirrors the creation of the 'PL/SQL Parser' page provided in the 'Sample Data Loading' app.

pastedImage_0.png

Background: I'm trying to use APEX_DATA_PARSER to parse an upload file csv/xlsx in preparation to insert data to an existing table. The instruction I am following is step one to parse the data in preparation to insert into my table. I am attempting to upload the attached csv/txt file. When I upload using my version, the header is placed in row 2, when I used the PL/SQL Parser Page, the headers are correctly placed in Row 1 (as a column header).

I have recreated the page twice on my own, and both times my uploaded file Headers show up on the 2nd row. When I use the version provided in the 'Sample Data Loading' app, it works fine. I have spent half a day ticking and tying my code to match the example, but I cannot seem to figure out why my headers are going to the 2nd row. I have literally copy/pasted the code from the examples to a new page with the same setup. I am clearly missing a step or a hidden item that I have not added?? Any Ideas?

I assume this is the data parsing the uploaded data which I copy/pasted directly from the example app:

-- The APEX_DATA_PARSER.PARSE function allows to "select" up to 300 columns (COL001 to COL300) from the

-- parsed file. This example uses the following parameters.

--

-- P_CONTENT the file content to be parsed as a BLOB

-- P_FILE_NAME the name of the file; only used to derive the file type.

-- P_ADD_HEADERS_ROW add the detected attribute names for XML or JSON files as the first row

-- P_XLSX_SHEET_NAME For XLSX workbooks. The name of the worksheet to parse. If omitted or NULL, the function will

-- use the first worksheet found.

--

select line_number, col001, col002, col003, col004, col005, col006, col007, col008, col009, col010

   -- more columns (col011 to col300) can be selected here.

from apex_application_temp_files f,

   table( apex\_data\_parser.parse(

              p\_content                     => f.blob\_content,

              p\_add\_headers\_row             => 'Y',

              p\_xlsx\_sheet\_name             => :P31\_XLSX\_WORKSHEET,

              p\_max\_rows                    => 500,

              p\_store\_profile\_to\_collection => 'FILE\_PARSER\_COLLECTION',

              p\_file\_name                   => f.filename ) ) p

where f.name = :P31_FILE

My Version of the Parsing Page - The CSV Column Headers show up on the 2nd Row:

pastedImage_1.png

Output when using the 'Sample Data Loading' app provided in the app downloads - CSV Headers show up on Row 1 as expected:

pastedImage_7.png

This post has been answered by Veerendra Patil on Nov 29 2019
Jump to Answer
Comments
Post Details
Added on Nov 28 2019
8 comments
2,717 views