quinnyke
quinnyke

Reputation: 15

PL/SQL UTL_FILE package read from csv and load values into a table

If I have a CSV file like this:

enter image description here

How can I read this with UTL_FILE package and load the values into one table which have columns: ItemIdentifier, SoldOnWeb, SoldInTheShop?

Upvotes: 0

Views: 409

Answers (1)

Littlefoot
Littlefoot

Reputation: 142710

From my point of view, as CSV files can be edited with MS Excel, I'd suggest you to rearrange the file and uniform it. The way it is now, it contains different headings and - to make it worse - they don't "match" (the same column contains itemidentifier and soldintheshop values; the same goes for the next column).

Add yet another column which would explain what the "sold..." column represents. Finally, you'd have something like this:

itemidentifier   amount   location
--------------   ------   -------------
1                10       soldOnWeb
2                7        soldOnWeb
3                5        soldOnweb
1                7        soldInTheShop
2                3        soldInTheShop

Doing so, it is a simple task to insert every value where it belongs.


Otherwise, can it be done in PL/SQL? Probably. Will it be difficult? Probably, as you have to "remember" what you're selecting in each row and - according to that - insert values into appropriate columns in the table.

You know how it goes ... garbage in, garbage out.

Upvotes: 2

Related Questions