0

Based in the csv file column header it should create table dynamically and also insert records of that csv file into the newly create table. Ex:

1) If i upload a file TEST.csv with 3 columns, it should create a table dynamically with three
2) Again if i upload a new file called TEST2.csv with 5 columns, it should create a table dynamically with five columns.

Every time it should create a table based on the uploaded csv file header..

how to achieve this in oracle APEX..

Thanks in Advance..

2 Answers 2

1

Without creating new tables you can treat the CSVs as tables using a TABLE function you can SELECT from. If you download the packages from the Alexandria Project you will find a function that will do just that inside CSV_UTIL_PKG (clob_to_csv is this function but you will find other goodies in here).

You would just upload the CSV and store in a CLOB column and then you can build reports on it using the CSV_UTIL_PKG code.

If you must create a new table for the upload you could still use this parser. Upload the file and then select just the first row (e.g. SELECT * FROM csv_util_pkg.clob_to_csv(your_clob) WHERE ROWNUM = 1). You could insert this row into an Apex Collection using APEX_COLLECTION.CREATE_COLLECTION_FROM_QUERY to make it easy to then iterate over each column.

You would need to determine the datatype for each column but could just use VARCHAR2 for everything.

But if you are just using generic columns you could just as easily just store one addition column as a name of this collection of records and store all of the uploads in the same table. Just build another table to store the column names.

0

Simply store this file as BLOB if structure is "dynamic". You can use XML data type for this use case too but it won't be very different from BLOB column. There is a SecureFile feature since 11g, It is a new BLOB implementation, it performs better than regular BLOB and it is good for unstructured or semi structured data.

Not the answer you're looking for? Browse other questions tagged or ask your own question.