问题描述
我允许用户通过OHS / mod_plsql上传.csv文件。此文件将作为BLOB文件保存在数据库中,然后我将其转换为CLOB。然后我想要获取这个CLOB文件的内容并将其内容保存到一个表中。我已经有一些工作代码,基于行结束分割文件,然后分割每个结果字符串,并以逗号和插入记录。
我需要的是一种方式来处理CSV中的字符串用双引号括起来并包含逗号的情况。例如:
col1,col2,col3,col4
some,text,more,text
this,text ,has,commas,semicolons,and periods
我的代码将知道如何处理第二行,有没有人有一些代码,足够聪明地处理逗号,分号和句点作为一个单一的标记?我可能可以在一起共事,但我不相信我的正则表达式的技能,我想别人可能已经写了一些东西做同样的事情,愿意分享。
更多信息:
I am allowing a user to upload a .csv file via OHS/mod_plsql. This file gets saved as a BLOB file in the database, which I then convert to CLOB. I want to then take the contents of this CLOB file and save its contents into a table. I already have some working code that splits the file based on line endings, then splits each resulting string along commas and inserts the records.
What I need is a way to handle the case where a string within the CSV is enclosed in double-quotes and contains a comma. For example:
col1,col2,col3,col4 some,text,more,text this,text,has,"commas, semicolons, and periods"
My code will know how to process the second line, but not the third. Does anyone have some code that is smart enough to treat "commas, semicolons, and periods" as a single token? I could probably hack something together, but I don't trust my regular expression skills enough, and I figure someone else has probably already written something that does this same thing that would be willing to share.
There's a good CSV parser in the Alexandria PL/SQL Library - CSV_UTIL_PKG.
https://code.google.com/p/plsql-utils/
More info:
http://ora-00001.blogspot.com.au/2010/04/select-from-spreadsheet-or-how-to-parse.html
这篇关于用于处理来自CLOB的CSV的Oracle PL / SQL包/过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!