简体   繁体   中英

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

If I have a CSV file like this:

在此处输入图像描述

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM