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!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Oracle Apex - PL/SQL - Apex_data_parser reading csv files

Jasper TanglibApr 14 2021

Hi,
In Oracle 20.2, I have a code that reads the csv file uploaded into wwv_flow_files. This will display the contents of a csv file which I would then use to insert into a table.
My code:
SELECT col001 RN, col002 INST_ID, col003 NAME, col004 VALUE, col005 DISPLAY_VALUE
FROM wwv_flow_files f,
TABLE ( apex_data_parser.parse(
p_content => f.blob_content,
p_store_profile_to_collection => 'FILE_PARSER_COLLECTION',
p_file_name => f.filename,
p_skip_rows => 2 ) ) p
WHERE name LIKE '%all_parameters.csv'

I'm expecting that the csv file is read like this (it is separated by a delimiter of 3 characters <,>). This is what it looks like when I open my csv file through notepad(.txt):
image.png
But using my code, the output of the csv file read is like this. The 4th and 5th column should actually be in only 1 column:
image.pngIf I open the csv file using its .csv extension, it looks like this. It is detecting the comma (,) as something else and splitting the values into different columns.
image.png

I tried adding the p_csv_delimiter in my parameter but it just made the data worse.
SELECT col001 RN, col002 INST_ID, col003 NAME, col004 VALUE, col005 DISPLAY_VALUE
FROM wwv_flow_files f,
TABLE ( apex_data_parser.parse(
p_content => f.blob_content,
p_store_profile_to_collection => 'FILE_PARSER_COLLECTION',
p_file_name => f.filename,
p_skip_rows => 2,
p_csv_row_delimiter => '<,>' ) ) p
WHERE name LIKE '%all_parameters.csv'
image.png
How can I have apex_data_parser.parse read my CSV file in the format it would have when opened in .txt extension.

Any ideas or suggestions as appreciated,
-Jazz

This post has been answered by jariola on Apr 14 2021
Jump to Answer

Comments

Naveent_2785

The below is working:

use JSON.parse() on the string and stored the output in a JSON object. Send the JSON object as a request to the REST reference

mateo91

Thanks! This helps!

Demetrius Brackens

Was javascript used to implement this solution? Do you have an example? Thanks.

mateo91

You must use the Javascript component after your transform component. Then you just add the JSON.parse() call on your JSON Object variable used in the Transform (e.g. JSON.parse(<jsonObjectVariable>);)
I ended up not even needing my Transform Component since I was receiving JSON in my request. Then I just used my Javascript component to parse what I needed in the receive payload before sending it off to the external destination.

Demetrius Brackens

Thanks for your help. This is working for me now.

Hi, I am having the same parsing issue. Can you show me example of JSON.parse(<jsonObjectVariable>);

mateo91

@User_489HG - Did you get this resolved? Let me know and I can provide an example. You can do this with both a JavaScript component and an Assign Component.

Maruthi Gottumukkala

Can you please provide me examples.

Maruthi Gottumukkala

Finally I figured it out. Appreciated for the tip. Thank you so much guys.

User_FRYTH

I am having the same issue kind of issue, in OSB 12c, when using xslt and nXSDTraslate, it shows output in binary format,
Then I have used commons-codec-1.7.jar to extract the string from binary format.
Now my rest api is not accepting the request, so I need to covert it from string to json then send it to REST api.
mateo91/User_489HG , Can you please share some example, how to do that.

1552110

After you Convert your XML to String using Translate activity, Add a JavaScript activity and add $JsonInput = JSON.parse($jsonInputString) to the Code snippet to convert the String to JSON object. In the example here $JsonInput vairiable is a JSON object input for my REST service call. Hope this helps.

User_FYU9P

Thanks for help. It is working

1 - 12

Post Details

Added on Apr 14 2021
5 comments
2,719 views