APEX 3.2:将数据从.CSV导出到Oracle DB

时间:2012-07-25 18:51:11

标签: oracle-apex

APEX 3.2 Oracle 11

我的要求是创建一个GUI进程,允许用户加载.CSV文件,该文件只有4列,可能有多行。然后使用.CVS文件中的相应数据更新数据库中的数据表。

CSV file:
ID Number:  Field Name:  Channel:   Analyst:
123456      Title         Retail    John Smith
123456      City          Retail    John Smith


Current DB:
ID Number:  Field Name:  Channel:   Analyst:
123456      Title         Retail    (null)
123456      City          (null)    (null)


After Update DB
ID Number:  Field Name:  Channel:   Analyst:
123456      Title         Retail    John Smith
123456      City          Retail    John Smith

感谢任何想法或链接。

1 个答案:

答案 0 :(得分:0)

提供文件浏览项,将文件上传到wwv_flow_files。

然后解析BLOB内容,请看这个链接:

http://christopherbeck.wordpress.com/2012/04/03/parsing-a-csv-file-in-plsql/

这些评论也值得一读。例如,提到了Alexendria PLSQL实用程序库。这个库包含许多基于plsql的工具,非常值得一试!

http://code.google.com/p/plsql-utils/

  

(引自Morten在博客中的评论)

     

克里斯,

     

正如我所指出的,最新版本的csv_util_pkg包可以   可以在亚历山大图书馆找到,这确实得到了支持   可选的封闭值。

     

我刚用你的示例数据测试过它:

 select * from table(csv_util_pkg.clob_to_csv(‘normal,”commas,,,in the
 field”,”"”enclosed”"”,”random “” double “” quotes”,”commas,,, “” and
 double “”"” quotes”‘))
     

这会将数据分成5列:

 c001 = normal c002 = commas,,,in the field c003 = “enclosed” c004 =
 random ” double ” quotes c005 = commas,,, ” and double “” quotes
     

(我想我应该从博客文章中删除旧代码   指导人们下载最新的库代码。)

     
      
  • 的Morten
  •   

另外,在评论中还显示了如何从blob转到clob(因此可以使用发布的方法。对Christopher Beck的信用):

  function blob_to_clob( p_lob in blob ) return clob is
     l_clob_result   clob := 'X';
     l_dest_offsset integer := 1;
     l_src_offsset  integer := 1;
     l_lang_context integer := dbms_lob.default_lang_ctx;
     l_warning      integer;
  begin
     if p_lob is not null and length(p_lob) > 0 then
        dbms_lob.converttoclob(dest_lob     => l_clob_Result,
                               src_blob     => p_lob,
                               amount       => dbms_lob.lobmaxsize,
                               dest_offset  => l_dest_offsset,
                               src_offset   => l_src_offsset,
                               blob_csid    => dbms_lob.default_csid,
                               lang_context => l_lang_context,
                               warning      => l_warning);
        if l_warning != 0 then
           dbms_output.put_line('Function blob_to_clob warning:' || l_warning);
           return null;
        end if;
        return l_clob_result;
     else
        return null;
     end if;
  exception
     when others then
        dbms_output.put_line('Function blob_to_clob error:' || SQLCODE);
        return null;
  end blob_to_clob;

您可以将列输出到全局临时表或集合,然后对此执行更新逻辑。 (小心GTT和apex。只要你在同一个会话中就没问题,但是如果你想让它成为第二个进程,则无法保证会使用相同的会话!)

相关问题