Suppose you want to read a file from D2k client and want to store its content in Oracle database. But if you will insert row by row from client to server it will take more time and increase lot of network traffic / round trips.

The solution of this problem is to store the content of the text file into an array and then pass it to database procedure and insert record through that procedure. Here is the example step by step:

1)  Create a package in Oracle database.

Create or Replace Package DB_insert
as
Type textrow is table of Varchar2(1000)
    index by binary_integer;

Procedure Insert_into_table (iarray in textrow);
End;
/

Create or Replace Package Body DB_insert 
as
Procedure Insert_into_table(iarray in textrow)
is
Begin
   For i in 1..iarray.count loop
       Insert into Dummytbl values (iarray(i));
       -- you can extract the content from iarray(i) to insert values into multiple fields
       -- e.g. iarray(i).fieldname
       --
   End Loop;
Commit;
End;
/

2)   Now in D2k write a procedure to read text file and store it into array and pass it to that package you crated above.

Procedure Read_File (ifilename in Varchar2)
is
infile Text_IO.File_type;
irow DB_insert.textrow; 
nelm number := 1;
Begin
   infile := text_io.fopen(ifilename, 'r');
Loop
     text_io.get_line(infile, irow(nelm));
     nelm := nelm + 1;
End Loop;
Exception
   when no_data_found then
     -- end of file reached
    text_io.fclose(infile);
   message('Read Completed.'); 
   -- pass it to database
   DB_insert.insert_into_table(irow);
  message('Data saved.');
  when others then
    if text_io.is_open(infile) then
       text_io.fclose(infile);
    end if;
   message(sqlerrm);   
End;

See also: Reading csv files with Text_io
http://foxinfotech.blogspot.com/2013/02/reading-and-importing-comma-delimited.html
   

Using Text_IO To Read Files in Oracle D2k的更多相关文章

  1. Reading Csv Files with Text_io in Oracle D2k Forms

    Below is the example to read and import comma delimited csv file in oracle forms with D2k_Delimited_ ...

  2. Obtaining Query Count Without executing a Query in Oracle D2k

    Obtaining Query Count Without executing a Query in Oracle D2k Obtaining a count of records that will ...

  3. Using Call_Form in Oracle D2k

    Using Call_Form in Oracle D2k CALL_FORM examples/* Example 1:** Call a form in query-only mode.*/BEG ...

  4. Using GET_APPLICATION_PROPERTY in Oracle D2k Forms

    Using GET_APPLICATION_PROPERTY in Oracle D2k Forms DescriptionReturns information about the current ...

  5. DISPLAY_ITEM built-in in Oracle D2k Forms

    DISPLAY_ITEM built-in in Oracle D2k Forms DescriptionMaintained for backward compatibility only. For ...

  6. Pre-Query trigger in Oracle D2k / Oracle Forms

    Pre-Query trigger in Oracle D2k / Oracle Forms DescriptionFires during Execute Query or Count Query ...

  7. Creating List Item in Oracle D2k

    Special Tips for List Items in Oracle D2k In this section, I shall discuss some special tips and tec ...

  8. Creating Object Library OLB in Oracle D2k Form

    With following steps you can create Object Library (OLB) in Oracle D2k Forms.Step - 1Create a form i ...

  9. Creating Timer in Oracle D2k / Forms 6i and Displaying a Clock

    Creating Timer in Oracle D2k / Forms 6i and Displaying a Clock This is about timer in D2k An externa ...

随机推荐

  1. 写sql语句分别按日,星期,月,季度,年统计

    --写sql语句分别按日,星期,月,季度,年统计销售额 --按日 ' group by day([date]) --按周quarter ' group by datename(week,[date]) ...

  2. Android自动化压力测试快速入门教程(图解)——MonkeyRunner

    一.MonkeyRunner测试环境配置(转自) 1.  android-sdk 下载地址:http://www.android-doc.com/sdk/index.html 下载完成后,只需要解压就 ...

  3. UIActivityViewController(转)

    在iOS 6之后提供了一个分享列表视图,它通过UIActivityViewController管理.苹果设计它主要的目的是替换分享动作选单(ActionSheet),分享动作选单是出于分享目的的动作选 ...

  4. iOS 警告窗口

    - (IBAction)buttonPressed:(id)sender {        NSDate *date=self.datePicker.date;    NSString *messag ...

  5. 使用SQLServer Profiler侦测死锁(转)

    准备工作: 为了侦测死锁,我们需要先模拟死锁.本例将使用两个不同的会话创建两个事务. 步骤: 1. 打开SQLServer Profiler 2. 选择[新建跟踪],连到实例. 3. 然后选择[空白] ...

  6. Linux设备模型(9)_device resource management ---devm申请空间【转】

    转自:http://www.wowotech.net/linux_kenrel/device_resource_management.html . 前言 蜗蜗建议,每一个Linux驱动工程师,都能瞄一 ...

  7. Temporary InMemory Tables [AX 2012]

    Temporary InMemory Tables [AX 2012] This topic has not yet been rated - Rate this topic Updated: Oct ...

  8. Centos7下卸载docker

    最近发现某台机器上的Docker服务无法开启,报如下错误: [root@localhost ~]# docker ps -a Cannot connect to the Docker daemon. ...

  9. yii2框架安装

    注意:先把php.ini里面的php_openssl.dll扩展打开 1.下载yii2框架的文件包yii-advanced-app-2.0.7 2.打开路径为advanced下面的init.bat   ...

  10. canvas 动画

    1.随机产生形状,做360度运转,带有一个开始开始按钮一个停止按钮 var canvas=$('.mycanvas'); canvas.attr("width",500);//$( ...