Skip to Main Content

SQL & PL/SQL

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!

Count number of fields in a CSV file record

687520Nov 1 2011 — edited Nov 2 2011
Hello,

Here is my problem. I need to open a CSV file on a directory and count the number of fields in a record. I can easily read the first record using UTL_FILE package, something like:

UTL_FILE.fopen (s_remote_dir, s_csv_file, 'R', 32767);
UTL_FILE.get_line (input_file, input_buffer);

then I count the number of commas in the buffer in order to get no. of fields:

IF input_buffer IS NOT NULL THEN
n := <function that counts number of commas in a string, input_buffer>
END IF;

However, this method will not work if a comma is present inside a field, i.e:

127763, "TRA account", 1001, 34, _"1007 main St., apt. 798"_
(last field contains a comma)

Please advise.

Regards,
M.R.
This post has been answered by Kim Berg Hansen on Nov 2 2011
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 30 2011
Added on Nov 1 2011
3 comments
941 views