将 .csv 文件导入 Oracle Forms 应用程序 [英] Importing .csv file into a Oracle Forms application

查看:26
本文介绍了将 .csv 文件导入 Oracle Forms 应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,如何将 .csv 文件导入 Oracle Forms 应用程序.我们在 Oracle 12c 数据库上使用 Oracle Forms 11g.

I've got a question how to import a .csv file into a Oracle Forms application. We are using Oracle Forms 11g on a Oracle 12c Database.

现在我们要使用 Forms 应用程序导入一个 .csv 文件,以便我们的客户可以导入此文件并将数据写入数据库.

Now we want to import a .csv file with the Forms applicationso our customers can import this file and write the data into the database.

我的计划是创建一个应用程序,用户可以在其中使用文件选择器导入 .csv 文件.将读取 .csv 中的数据,并且输出向用户显示此应用程序中的数据.然后用户应该可以通过一个按钮将其保存到数据库中.

My plan is to create an application where the user can import a .csv file with a filechooser. The data from the .csv will be read and an output shows the user the data in this application. Then the user should be able to save it into the database through a button.

我已经尝试了几次搜索,但没有找到解决此类问题的正确方法.我发现的唯一解决方案是将 .csv 文件直接导入数据库,但不是通过 Oracle Forms

I've tried several searches but haven't found the right solution for this kind of problem. The only solutions I've found were a direct import of a .csv file into a database but not through Oracle Forms

是否可以在 Oracle Forms 中加载 .csv 文件?

Is it even possible to load .csv files in Oracle Forms?

如果有人有好的解决方案或其他任何可能有用的东西,我将不胜感激.

If anyone has a good solution or anything else that might be helpfull i would be thankfull for that.

推荐答案

我现在找到了适合我的解决方案.也许我可以做得更好,但到目前为止这对我有帮助.

I've found a suitable solution for me now. Maybe I could do it better but this helps me so far.

我找到了以下博客:http://tfathy.blogspot.de/2009/03/reading-from-file.html

代码通过复制和粘贴 100% 工作,并从现在开始帮助我完成任务.

The Code works 100% by copy&paste and helps me from now on to complete the task.

也许它也可以帮助其他人.

Maybe it might help anyone else too.

这是解决方案代码:

Reading From File 
March 19, 2009
--------------------------------------------------
Declare
  vfilename varchar2(500);
  in_file   Client_Text_IO.File_Type;
  linebuf   VARCHAR2(1800); 
BEGIN
    vfilename := client_get_file_name('c:/temp/', File_Filter=>'Comma Dialimeted Files (*.csv)|*.csv|'); 
    in_file := client_Text_IO.Fopen(vfilename, 'r');  
    GO_BLOCK('Emp'); 
    FIRST_RECORD;  
  LOOP
    Client_Text_IO.Get_Line(in_file, linebuf); 
    p_output_line(linebuf);
    Client_Text_IO.New_Line; 
    Next_record; 
  END LOOP; 
   FIRST_RECORD;
EXCEPTION
  WHEN no_data_found THEN
    Client_Text_IO.Put_Line('Closing the file...');
    Client_Text_IO.Fclose(in_file);
END;
-------------------------------------------------------
PROCEDURE p_output_line(p_line varchar2) IS 
vLINE VARCHAR2(4000);
vVALUE VARCHAR2(1000); 
vCOMMA_COUNT NUMBER;
vREPORT_DATE DATE;
BEGIN                    
 vLINE := p_line;
 vCOMMA_COUNT := LENGTH(vLINE)- LENGTH(REPLACE(vLINE,',','')); -- COUNT THE NUMBER OF COMMAS
  FOR I IN 1.. vCOMMA_COUNT+1 LOOP  
   vVALUE := SUBSTR(vLINE,1,INSTR(vLINE,',')-1);                             -- IF vLINE = 123,ABC,9877 THEN VVALUE WILL BE  123
    IF vVALUE IS NULL THEN
        vVALUE := vLINE;
    END IF;    
   vLINE := SUBSTR(vLINE,INSTR(vLINE,',')+1) ;                              -- CHANGE   123,ABC,9877 TO BE   ABC,9877  
   IF I = 1 THEN 
    :DATA.BMK_NAME := vVALUE; 
   ELSIF I = 2 THEN 
    vREPORT_DATE := last_day(to_date(vVALUE,'dd-mm-yyyy')); 
    :DATA.REPORT_DATE := vREPORT_DATE;
   ELSIF I = 3 THEN                 
    :DATA.BMK_RETURN := to_number(vVALUE);
   END IF;
  END LOOP; 
  EXCEPTION
    WHEN NO_DATA_FOUND THEN
    MESSAGE('Please Check the data type is appropriate on you excel file');
    MESSAGE('Please Check the data type is appropriate on you excel file');
END; 
-----------------------------------------------------------------------
-- notes
1- you must install webutil version 106 or later
2- make sure that you attached and compiled the webutill.pll scucessfuly

这篇关于将 .csv 文件导入 Oracle Forms 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆